Skip to content

Commit

Permalink
[flow][multiplat] Support nominal renders in common interface files
Browse files Browse the repository at this point in the history
Summary:
Followup of D66711903. We need to do this for render as well. Unlike the component subtyping case, we do not need to do a component structural subtyping checking here, since the same check would already be done during the common interface conformance check

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D66887907

fbshipit-source-id: fc7a59e25060e531bfb92015b8335f2bd42aa479
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Dec 7, 2024
1 parent 0098c07 commit e84f7c7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/typing/renders_kit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ module Make (Flow : INPUT) : S = struct
explanation = None;
}
)
| ( NominalRenders { renders_id = id1; renders_name = _; renders_super },
NominalRenders { renders_id = id2; renders_name = _; renders_super = _ }
| ( NominalRenders { renders_id = id1; renders_name = name_1; renders_super },
NominalRenders { renders_id = id2; renders_name = name_2; renders_super = _ }
) ->
if ALoc.equal_id id1 id2 then
if
ALoc.equal_id id1 id2
||
let file_options = Context.((metadata cx).file_options) in
TypeUtil.nominal_id_have_same_logical_module
~file_options
(id1, Some name_1)
(id2, Some name_2)
then
()
else
(* We reposition the super using l's reason for better error messages *)
Expand Down
6 changes: 5 additions & 1 deletion tests/multiplatform_subtyping/component.ios.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
declare export component Foo(bar: string, baz: number); // incompatible-type with baz prop, otherwise ok
declare export component Foo(bar: string, baz: number) renders Base; // incompatible-type with baz prop, otherwise ok
declare component Base();
declare component Acid();

declare export component DifferentRenders() renders Acid; // error: incompatible renders type
5 changes: 4 additions & 1 deletion tests/multiplatform_subtyping/component.js.flow
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
declare export component Foo(bar: string, baz: boolean)
declare export component Foo(bar: string, baz: boolean) renders Base;
declare component Base();

declare export component DifferentRenders() renders Base;
24 changes: 20 additions & 4 deletions tests/multiplatform_subtyping/multiplatform_subtyping.exp
Original file line number Diff line number Diff line change
Expand Up @@ -449,18 +449,34 @@ Read the docs on Flow's multi-platform support for more information: https://flo
[incompatible-type]

component.ios.js:1:26
1| declare export component Foo(bar: string, baz: number); // incompatible-type with baz prop, otherwise ok
1| declare export component Foo(bar: string, baz: number) renders Base; // incompatible-type with baz prop, otherwise ok
^^^

References:
component.js.flow:1:48
1| declare export component Foo(bar: string, baz: boolean)
1| declare export component Foo(bar: string, baz: boolean) renders Base;
^^^^^^^ [1]
component.ios.js:1:48
1| declare export component Foo(bar: string, baz: number); // incompatible-type with baz prop, otherwise ok
1| declare export component Foo(bar: string, baz: number) renders Base; // incompatible-type with baz prop, otherwise ok
^^^^^^ [2]


Error -------------------------------------------------------------------------------------------- component.ios.js:5:45

Cannot conform to common interface module because `Acid` [1] does not render `Base` [2] in property `DifferentRenders`.
Read the docs on Flow's multi-platform support for more information: https://flow.org/en/docs/react/multiplatform.
[incompatible-type]

component.ios.js:5:45
5| declare export component DifferentRenders() renders Acid; // error: incompatible renders type
^^^^^^^^^^^^ [1]

References:
component.js.flow:4:45
4| declare export component DifferentRenders() renders Base;
^^^^^^^^^^^^ [2]


Error ----------------------------------------------------------------------------------------------- enums.ios.js:11:21

Cannot conform to common interface module because `FooBad` [1] is incompatible with `FooBad` [2] in property `FooBad`.
Expand Down Expand Up @@ -670,4 +686,4 @@ References:



Found 37 errors
Found 38 errors

0 comments on commit e84f7c7

Please sign in to comment.