-
Notifications
You must be signed in to change notification settings - Fork 469
Fix issue where build error of newtype escaping its scope #6000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
|
||
function Newtype_props_component_test$C1(props) { | ||
return props.foo; | ||
} | ||
|
||
var C1 = { | ||
make: Newtype_props_component_test$C1 | ||
}; | ||
|
||
function Newtype_props_component_test$C2(props) { | ||
return props.foo; | ||
} | ||
|
||
var C2 = { | ||
make: Newtype_props_component_test$C2 | ||
}; | ||
|
||
exports.C1 = C1; | ||
exports.C2 = C2; | ||
/* No side effect */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@@bs.config({ | ||
flags: ["-bs-jsx", "4"], | ||
}) | ||
|
||
module type T = { | ||
type t | ||
} | ||
|
||
module C1 = { | ||
@react.component | ||
let make = (type a, ~foo: module(T with type t = a)) => { | ||
module T = unpack(foo) | ||
foo | ||
} | ||
} | ||
|
||
module C2 = { | ||
@react.component | ||
let make = (type a, ~foo) => { | ||
module T = unpack(foo: T with type t = a) | ||
foo | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,10 @@ module Select = { | |
type key | ||
type t | ||
} | ||
type props<'model, 'selected, 'onChange, 'items> = { | ||
type key | ||
and a | ||
|
||
and props<'model, 'selected, 'onChange, 'items> = { | ||
model: 'model, | ||
selected: 'selected, | ||
onChange: 'onChange, | ||
|
@@ -67,10 +70,10 @@ module Select = { | |
@react.component | ||
let make = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this should be let make = (type a, ... |
||
{model, selected, onChange, items, _}: props< | ||
module(T with type t = '\"type-a" and type key = '\"type-key"), | ||
option<'\"type-key">, | ||
option<'\"type-key"> => unit, | ||
array<'\"type-a">, | ||
module(T with type t = a and type key = key), | ||
option<key>, | ||
option<key> => unit, | ||
array<a>, | ||
>, | ||
) => { | ||
let _ = (model, selected, onChange, items) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This declares a new type a in the current scope. Will error if a type called a is already in scope. Eg defined just above.
The (type a) should be confined to the body of make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so too. I want to avoid to add type declaration. But I don't have a clear idea to fix this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it compiles OK, should be good.
Might be worth testing a couple of examples by hand and see that it compiles OK, before changing the ppx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That
: props<'foo>
should be: props<_>
I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, It works. But How can JSX4 know that foo is going be unpack in the body expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current ppx passes the core_type of argument to props type. Do you mean passing no parameter to props type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no that should stay the same.
I think above you want
let make = (type a, ... : props<a>