-
Notifications
You must be signed in to change notification settings - Fork 469
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 all 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
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,31 @@ | ||
'use strict'; | ||
|
||
|
||
function Alias_default_value_test$C0(props) { | ||
var a = props.a; | ||
var a$1 = a !== undefined ? a : 2; | ||
var b = props.b; | ||
var b$1 = b !== undefined ? b : (a$1 << 1); | ||
return a$1 + b$1 | 0; | ||
} | ||
|
||
var C0 = { | ||
make: Alias_default_value_test$C0 | ||
}; | ||
|
||
function Alias_default_value_test$C1(props) { | ||
var foo = props.foo; | ||
if (foo !== undefined) { | ||
return foo; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
var C1 = { | ||
make: Alias_default_value_test$C1 | ||
}; | ||
|
||
exports.C0 = C0; | ||
exports.C1 = C1; | ||
/* No side effect */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@@bs.config({ | ||
flags: ["-bs-jsx", "4"], | ||
}) | ||
|
||
module C0 = { | ||
@react.component | ||
let make = (~a=2, ~b=a * 2) => { | ||
React.int(a + b) | ||
} | ||
} | ||
|
||
module C1 = { | ||
@react.component | ||
let make = (~foo as bar="") => { | ||
React.string(bar) | ||
} | ||
} |
Large diffs are not rendered by default.
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) => React.int(a + b) | ||
} | ||
|
||
module C1 = { | ||
@react.component | ||
let make = (~a=2, ~b) => React.int(a + b) | ||
} |
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 a = switch props.a { | ||
| Some(a) => a | ||
| None => 2 | ||
} | ||
let b = switch props.b { | ||
| 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 |
||
} | ||
|
||
React.int(a + b) | ||
} | ||
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 a = switch props.a { | ||
| Some(a) => a | ||
| None => 2 | ||
} | ||
let b = props.b | ||
|
||
React.int(a + b) | ||
} | ||
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.
Given the error message I'm getting "The module or file props can't be found." this is probably a path
A.foo
whereA
happens to beprops
and not a field access, which it should be.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.
Field access is
Pexp_field
.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.
Oops! Correct.