Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345827

Summary: [xtend] illegal parameter passing
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: RC1   
Hardware: All   
OS: All   
Whiteboard:

Description Knut Wannheden CLA 2011-05-14 16:31:25 EDT
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.
Comment 1 Sebastian Zarnekow CLA 2011-05-15 04:58:50 EDT
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.
Comment 2 Sven Efftinge CLA 2011-05-15 05:06:53 EDT
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 :-)
Comment 3 Sven Efftinge CLA 2011-05-15 05:08:56 EDT
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.
Comment 4 Sven Efftinge CLA 2011-05-15 05:15:49 EDT
If the check I added becomes superfluous by the fix in the scoping please remove it.
Comment 5 Sebastian Zarnekow CLA 2011-05-16 03:57:01 EDT
Pushed the scoping changes to master.
Comment 6 Karsten Thoms CLA 2017-09-19 17:40:13 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 17:51:27 EDT
Closing all bugs that were set to RESOLVED before Neon.0