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

Bug 342919

Summary: [xtend] Undetected syntax error leading to uncompilable code
Product: [Tools] Xtend Reporter: Karsten Thoms <karsten.thoms>
Component: CoreAssignee: Project Inbox <xtend-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.3.0Flags: sven.efftinge: kepler+
Target Milestone: M6   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:
Bug Depends on: 376037    
Bug Blocks:    

Description Karsten Thoms CLA 2011-04-15 01:36:04 EDT
Steps to reproduce:
- Use Domainmodel example
- Change implementation of body() to:

  body(Entity e) {
    '''
    public class «e.name» «e.superTypeClause()»{
      «e.features.map(f|f.feature).flatten»
    }
    '''
  }


This will lead to the following code:
    List<StringConcatenation> _map = ListExtensions.<Feature, StringConcatenation>map(_features, _function);
    Iterable<?> _flatten = IterableExtensions.flatten(_map);

and this syntax error in the Java code:
The method flatten(Iterable<? extends Iterable<? extends T>>) in the type IterableExtensions is not applicable for the arguments (List<StringConcatenation>)
Comment 1 Sebastian Zarnekow CLA 2012-12-05 18:21:16 EST
What do you mean by 'implementation of body()'?. Which class are you referring to?
Comment 2 Karsten Thoms CLA 2012-12-06 17:46:16 EST
Previous versions of the Domainmodel example had a Xtend Rich String based code generator as example (which version was current in April last year?).

I tried to reproduce it with the Fowler example. I get another error when I insert this into StatemachineGenerator.xtend#toJavaCode(Statemachine sm):

    «sm.commands.map(c|c.declareCommand).flatten»

    Incompatible receiver type. Expected java.lang.Iterable<? extends java.lang.Iterable<? extends T>> or java.lang.Iterable<? extends T>[] but was java.util.List<java.lang.CharSequence>

"declareCommand" infers CharSequence as return type, thus I would expect that "sm.commands.map(c|c.declareCommand)" results into Iterable<CharSequence>, which should be a valid argument for the flatten() method.
Comment 3 Sven Efftinge CLA 2012-12-07 02:54:42 EST
(In reply to comment #2)
> "declareCommand" infers CharSequence as return type, thus I would expect
> that "sm.commands.map(c|c.declareCommand)" results into
> Iterable<CharSequence>, which should be a valid argument for the flatten()
> method.

flatten is defined like this :

  public static <T> Iterable<T> flatten(Iterable<? extends Iterable<? extends T>> inputs) {

So I'd say the error message is correct.
Comment 4 Karsten Thoms CLA 2012-12-07 05:55:40 EST
Right, did not think about that correctly.

So I guess this was not checked properly before and was just compiled, which resulted in the uncompilable code. Thus, I'd consider this as fixed in the meantime.
Comment 5 Eclipse Webmaster CLA 2017-10-31 11:05:11 EDT
Requested via bug 522520.

-M.
Comment 6 Eclipse Webmaster CLA 2017-10-31 11:16:32 EDT
Requested via bug 522520.

-M.