-
Notifications
You must be signed in to change notification settings - Fork 470
Fix issues with overlapping argument name and default value, using alias and default value together #5989
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
Fix issues with overlapping argument name and default value, using alias and default value together #5989
Changes from 3 commits
c673fc8
a415dbe
9916513
6abbae7
875834c
ec49a4b
edcf127
6c0a0bb
ba92bfa
d36ce45
91ead84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@@jsxConfig({version: 4}) | ||
|
||
module C0 = { | ||
let a = 1 | ||
@react.component | ||
let make = (~a=2, ~b=a * 2) => { | ||
let _ = a + b | ||
React.null | ||
} | ||
} | ||
|
||
module C1 = { | ||
@react.component | ||
let make = (~foo as bar="") => { | ||
let _ = bar | ||
React.null | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module C0 = { | ||
@react.component | ||
let make = (~a=2, ~b=a*2) => <div /> | ||
} | ||
|
||
module C1 = { | ||
@react.component | ||
let make = (~a=2, ~b) => <div /> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module C0 = { | ||
type props<'a, 'b> = {a?: 'a, b?: 'b} | ||
@react.component | ||
let make = (props: props<'a, 'b>) => { | ||
let b = switch props.b { | ||
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. Given the error message I'm getting "The module or file props can't be found." this is probably a path 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. Field access is 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. Oops! Correct. |
||
| Some(b) => b | ||
| None => a * 2 | ||
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. If you copy paste this, you'll get a 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. Actually, @react.component
let make = (~a=2, ~b=a*2) => <div /> So, 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. This is quite tricky than I guess. It has to be affected by the order, but it should not. let make = (props) => {
let a = 2 // 1
let b = a * 2 // <- a should be reference to the outside of make function, but it refers to 1 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. We transform the optional labelled argument to nolabel argument |
||
} | ||
and a = switch props.a { | ||
| Some(a) => a | ||
| None => 2 | ||
} | ||
|
||
ReactDOM.jsx("div", {}) | ||
} | ||
let make = { | ||
let \"DefaultValueProp$C0" = (props: props<_>) => make(props) | ||
\"DefaultValueProp$C0" | ||
} | ||
} | ||
|
||
module C1 = { | ||
type props<'a, 'b> = {a?: 'a, b: 'b} | ||
|
||
@react.component | ||
let make = (props: props<'a, 'b>) => { | ||
let b = props.b | ||
and a = switch props.a { | ||
| Some(a) => a | ||
| None => 2 | ||
} | ||
|
||
ReactDOM.jsx("div", {}) | ||
} | ||
let make = { | ||
let \"DefaultValueProp$C1" = (props: props<_>) => make(props) | ||
|
||
\"DefaultValueProp$C1" | ||
} | ||
} |
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.
Can you add this under
jscomp/test
instead? So it's compiler any timemake lib
is run, and you get normal error messages instead of a failed build test.It would look like 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.
To me it gives "The module or file props can't be found.".
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.
And same error if I write it in some other project that installs this version of the compiler.
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.
Notice
@@bs.config
, as@@jsxVersion
would not be picked up by a singlebsc
invocation used to run tests.