Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328845 - Different behavior between compiler and runtime evaluation
Summary: Different behavior between compiler and runtime evaluation
Status: CLOSED FIXED
Alias: None
Product: Acceleo
Classification: Modeling
Component: Core (show other bugs)
Version: 3.0.0   Edit
Hardware: PC Linux
: P3 major
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-27 11:31 EDT by Mikaël Barbero CLA
Modified: 2011-04-13 04:41 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mikaël Barbero CLA 2010-10-27 11:31:34 EDT
Hi,

I noticed a difference between the compiler and the runtime evaluation of a script. Here is an example that shows the issue:

[module workflow('http://www.eclipse.org/emf/2002/Ecore')/]

[template public main(a : EClass)]
  [let idFeature : EAttribute = eIDAttribute]
[sub()/]
  [/let]
[/template]

[template public sub(a : EStructuralFeature)]
Feature [name/]
[/template]

The compiler never complains but the runtime never goes into sub() template! I have to modify the call into the sub() to [idFeature.sub()/]

It seems that idFeature is pushed as the new 'self' in the compiler while it is not in the runtime evaluation. I don't have any clue about who is rightful but it should coherent ;) (or at least the runtime should throw an exception instead of silently doing nothing)

Best regards,
Mikael
Comment 1 Laurent Goubet CLA 2011-01-25 08:18:09 EST
The accurate behavior here is the engine's : neither "if" nor "let" change the context of an evaluation. We have to provide a compilation error for such uses.
Comment 2 Stephane Begaudeau CLA 2011-04-06 08:35:40 EDT
>> I don't have any clue about who is rightful but it should coherent

>> The accurate behavior here is the engine's

I don't know who's right here between the parser and the engine but since we just have to pick one and since, if the engine is right, I just have to remove four lines of code in the parser, let's say the engine is right, it's easier that way :D

"Let" and "For" blocks will not change the context anymore in the parser. Unit tests have also been added to ensure the non regression.

The fix has been contributed on HEAD. It will be available in Acceleo 3.1.0M7.
Comment 3 Stephane Begaudeau CLA 2011-04-12 02:56:43 EDT
I am reopening this issue since, after careful evaluation, the previous solution is not an option for several reasons:

1- this problem does not appear all the time since most of the time the parser will transform the template/query call with an implicit variable to a template/query call with the "current" self as an explicit variable and the engine will not complain. With the previous patch, all those call are now treated as error and we will create a situation in which valid module in Acceleo 3.0.x would have dozens of errors starting with Acceleo 3.1.0M7 (see the EEF project 130+ errors with this fix).

2- even if there are no errors, the previous fix can change the behavior of the generator:

[template public a(myClass : EClass)]
[for (myOperation : EOperation | myClass.eAllOperations)]
[b()/]
[/for]
[/template]

[template public b(myNamedElement : ENamedElement)]
[myNamedElement.name/]
[/template]

This would previously generate the name of all the operations of the given class, now it would generate the name of the class. It does not seem very clear/logical while reading the template "a" (one could reasonably argue that implicit call are never very clear in the first place). This produce very complex error in existing generators (again, see the EEF project).

The bug raised by Mikael appears only in minor cases since (as stated in "1") most of the time the engine does not now that the call is using an implicit variable. The behavior of the parser will be restored right now, the unit tests that have been contributed will be adapted and the engine will have to adapt even if it shouldn't even know about the existence of an implicit call. The parser should resolve the variables of those calls in the first place.
Comment 4 Stephane Begaudeau CLA 2011-04-13 04:41:23 EDT
Closing this one again. The new behavior is:

-> template/queries/for are creating a new context
-> if/let are not creating a new context