Hi, I tried to analyze this piece of code usign RECODER:
Collection<Integer> numbers = new ArrayList<Integer>();
numbers.add((Integer) num);
this.numbers = new int[numbers.size()];
int c = 0;
for (Number n : numbers) {
this.numbers[c++] = n.intValue();
}
I got the following error:
+++ Error: TypingException - lhs does not match rhs - java.lang.Number :
java.util.Collection<java.lang.Integer> - exp: numbers - 35/25 - - -
recoder.service.SemanticsChecker$SemanticsCheckerVisitor.visitEnhancedFor(Sema
nticsChecker.java:163)
recoder.java.statement.EnhancedFor.accept(EnhancedFor.java:117)
recoder.service.SemanticsChecker.check(SemanticsChecker.java:105)
recoder.service.SemanticsChecker.checkAllCompilationUnits(SemanticsChecker.jav
a:92)
...
(Error occurred outside a model update)
I started to debug the code and it seems that Number isn't a supertype of
Integer according to:
public boolean isSubtype(ClassType a, ClassType b)
method of class recoder.service.DefaultProgramModelInfo. During the debug
parameter a value was Number type and parameter b value was Integer type.
I tried to add this piece of code at line 546 of the above method:
}else if (b.getSupertypes().contains(a)){
return true;
}
After this change Number is recognized as a supertype of Integer but it isn't
the right way to do it because it makes other typing errors appear.
Thanks a lot :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I tried to analyze this piece of code usign RECODER:
I got the following error:
+++ Error: TypingException - lhs does not match rhs - java.lang.Number :
java.util.Collection<java.lang.Integer> - exp: numbers - 35/25 - - -
recoder.service.SemanticsChecker$SemanticsCheckerVisitor.visitEnhancedFor(Sema
nticsChecker.java:163)
recoder.java.statement.EnhancedFor.accept(EnhancedFor.java:117)
recoder.service.SemanticsChecker.check(SemanticsChecker.java:105)
recoder.service.SemanticsChecker.checkAllCompilationUnits(SemanticsChecker.jav
a:92)
...
(Error occurred outside a model update)
I started to debug the code and it seems that Number isn't a supertype of
Integer according to:
method of class recoder.service.DefaultProgramModelInfo. During the debug
parameter a value was Number type and parameter b value was Integer type.
I tried to add this piece of code at line 546 of the above method:
After this change Number is recognized as a supertype of Integer but it isn't
the right way to do it because it makes other typing errors appear.
Thanks a lot :-)
I think the problem is the call to isWidening inside
recoder.service.SemanticsChecker at line 156, visitEnhancedFor method.
It seems that it checks if lhsType (initializer) is a subtype of ct (guard)
but it should check if ct is a subtype of lhsType.
Correct. It's a bug. Please use the bug tracker for those :)
Fixed in SVN / next release.