Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 356074 - Dispatch should consider only arguments of different types...
Summary: Dispatch should consider only arguments of different types...
Status: CLOSED WORKSFORME
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-29 09:23 EDT by Serano Colameo CLA
Modified: 2017-09-19 17:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Serano Colameo CLA 2011-08-29 09:23:24 EDT
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.
Comment 1 Serano Colameo CLA 2011-08-29 09:25:57 EDT
(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);
	  }
	  ...
	  ..
	  .
}
Comment 2 Sven Efftinge CLA 2011-08-29 09:32:31 EDT
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.
Comment 3 Serano Colameo CLA 2011-08-30 04:07:36 EDT
(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
Comment 4 Karsten Thoms CLA 2017-09-19 17:18:42 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:30:02 EDT
Closing all bugs that were set to RESOLVED before Neon.0