Community
Participate
Working Groups
Build Identifier: Xtext 2.0.1 Dispatch methods do not consider arguments which are null. In other words, an input argument can be null. Therefore either the dispatch method allows to pass null-arguments or the xtend2 generator generates a java dispatch method which considers only argumetns of different types. As example, for the following methdos only the 1st argument has to be considered for the dispatch logic (the other argumetns should be taken as is, even if null): Xtend2: def dispatch getTypeName(InlineType type, Cardinality cardinality, String pkgName) def dispatch getTypeName(JvmField type, Cardinality cardinality, String pkgName) I would then expect the following java code: public StringConcatenation getTypeName(final Object type, final Cardinality cardinality, final String pkgName) { if (type instanceof JvmField) { return _getTypeName((JvmField)type, cardinality, pkgName); } else if (type instanceof InlineType) { return _getTypeName((InlineType)type, (Cardinality)cardinality, (String)pkgName); } ... .. . } ~serano Reproducible: Always Steps to Reproduce: 1. see details 2. 3.
(In reply to comment #0) > Build Identifier: Xtext 2.0.1 > > Dispatch methods do not consider arguments which are null. > > In other words, an input argument can be null. Therefore either the dispatch > method allows to pass null-arguments or the xtend2 generator generates a java > dispatch method which considers only argumetns of different types. > > As example, for the following methdos only the 1st argument has to be > considered for the dispatch logic (the other argumetns should be taken as is, > even if null): > > Xtend2: > > def dispatch getTypeName(InlineType type, Cardinality cardinality, String > pkgName) > def dispatch getTypeName(JvmField type, Cardinality cardinality, String > pkgName) > > I would then expect the following java code: > > public StringConcatenation getTypeName(final Object type, final Cardinality > cardinality, final String pkgName) { > if (type instanceof JvmField) { > return _getTypeName((JvmField)type, cardinality, pkgName); > } else if (type instanceof InlineType) { > return _getTypeName((InlineType)type, (Cardinality)cardinality, > (String)pkgName); > } > ... > .. > . > } > > ~serano > > > Reproducible: Always > > Steps to Reproduce: > 1. see details > 2. > 3. ...sorry, here again the example public StringConcatenation getTypeName(final Object type, final Cardinality cardinality, final String pkgName) { if (type instanceof JvmField) { return _getTypeName((JvmField)type, cardinality, pkgName); } else if (type instanceof InlineType) { return _getTypeName((InlineType)type, cardinality, pkgName); } ... .. . }
The behavior is intended. If you want to catch null you need to declare a dispatch method for the type 'Void'. dispatch myFunction(Void x) { // handle null case } Otherwise you will run in a IllegalArgumentException. i.e. not nullable is the default.
(In reply to comment #2) > The behavior is intended. > If you want to catch null you need to declare a dispatch method for the type > 'Void'. > > dispatch myFunction(Void x) { > // handle null case > } > > Otherwise you will run in a IllegalArgumentException. i.e. not nullable is the > default. ok, this means, that we either do not use dispatch for methods with more than one argument (which can be null) or we have to implement our own dispatch method to handle this case. ~serano
Closing all bugs that were set to RESOLVED before Neon.0