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

Bug 316583

Summary: StackOverflow when trying to call a "super" template
Product: [Modeling] Acceleo Reporter: Pierre-Charles David <pierre-charles.david>
Component: CoreAssignee: Project Inbox <acceleo-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: laurent.goubet
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Pierre-Charles David CLA 2010-06-11 05:42:37 EDT
Build Identifier: 20100603-0907

I have types A and B, B a subtype of A, and the following template on A:

[template public genText(a : A)]
text for A
[/template]

I want to create a new template of the same name on B, and in that template, call the code for genText(a : A).

I tried:

[template public genText(b : B)]
[b.A::genText()/]
text for B
[/template]

expecting to force a static resolution of the actual template to invoke by using the full classified name, but this raises a StackOverflowException, as b.A::genText() seems to resolve the template on the dynamic type of b and call genText(b : B).

Marking as enhancement as I'm not sure what the spec says.


Reproducible: Always
Comment 1 Laurent Goubet CLA 2016-03-21 06:44:58 EDT
Acceleo will always call the most specific template.

[b.A::genText()/] will result in the same as [b.oclAsType(A).genText()/]. The compiled template invocation indeed points to calling the "genText(A)" version, but at runtime we always check whether there's a more specific template we can call; so these two are exactly the same as calling directly [b.genText()/] in the present case.

The specification says nothing about which template to call in case of multiple templates sharing the same name but having distinct parameters.

A workaround in this case would be to create a third template and calling it from both :

[template public genText(a : A)]
[a.commonText()/]
[/template]

[template public genText(b : B)]
[b.commonText()/]
text for B
[/template]

[template public commonText(a : A)]
text for A
[/template]

Marking as won't fix as this behavior is not planned to be changed.