| Summary: | wrong generated java class in Xtend2 (=>cannot cast from null to int) | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Serano Colameo <serano.colameo> |
| Component: | Xtext | Assignee: | Jan Koehnlein <jan> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | minor | ||
| Priority: | P3 | CC: | jan, jos.warmer, sebastian.zarnekow, tmf.xtext-inbox |
| Version: | unspecified | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | SR1 | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
Xtend code:
var String empty = null;
var int i = empty?.length
Generated Java code:
String empty = null;
int _length = empty==null?(int)null:empty.length();
int i = _length;
Added default values for primitives to compiler and interpreter and a test.
Two notes:
1) We don't have special treatment for extensions: if the syntactic receiver is null, we don't evaluate the function, e.g.
def foo() {
(null as String)?.bar()
}
def bar(String x) {}
will not execute bar()
2) I've added a validation rule such that ?. is invalid on primitive receivers
Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
Build Identifier: Xtext 2.0.0.v201105241033 xtend2: def String getExpression(ConstExp exp) { switch exp.expr { /* value field is a primitice 'int' type*/ IntLiteral : (exp?.expr as IntLiteral)?.value?.toString ... } } generated java: public String getExpression(final ConstExp exp) { String _switchResult = null; ConstExp _expr = exp.getExpr(); final ConstExp __valOfSwitchOver = _expr; boolean matched = false; if (!matched) { if (__valOfSwitchOver instanceof IntLiteral) { matched=true; ConstExp _expr_1 = exp==null?(ConstExp)null:exp.getExpr(); int _value = ((IntLiteral) _expr_1)==null?(int)null:((IntLiteral) .... // ^^^^ cannot cast from null to int) } Reproducible: Always