| Summary: | [xtend] illegal parameter passing | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Knut Wannheden <knut.wannheden> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sebastian.zarnekow, sven.efftinge |
| Version: | 2.0.0 | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | RC1 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
This bug indicates a problem in the scoping implementation:
def String stuff(String stuff) {
var s = stuff("foo")
-----
}
The underlined stuff resolves to the parameter stuff instead of the function with the same name.
I've added a check. The editor now tells you that you cannot pass arguments to a local variable.
I also added checks to validate that side effect free expressions are not allowed in blocks at position n-1.
I.e.
{
val g = 3
g;
(3)
}
wouldn't compile neither because 'f' doesn't do anything at that position.
Thanks for all the good scenarios :-)
sorry we had a mid-air collision (on sunday?). The problem you describe is worth another ticket. It at least doesn't conflict with what I did :-) I've reopen the ticket so feel free to create a new ticket or do it with this one. (In reply to comment #1) > This bug indicates a problem in the scoping implementation: > > def String stuff(String stuff) { > var s = stuff("foo") > ----- > } > > The underlined stuff resolves to the parameter stuff instead of the function > with the same name. If the check I added becomes superfluous by the fix in the scoping please remove it. Pushed the scoping changes to master. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
The following Xtend2 snippet: def foo() { val f = [Integer e|e.toString] f(3) } seems to be perfectly valid (no error markers). But it may not do what the user might think: The method simply returns the closure. The user probably meant to write "f.apply(3)". I think this should actually be flagged as an error. Just like for instance: def foo() { val g = 3 g(3) } This currently doesn't give any errors either.