| Summary: | [xtend2] Primitive equality generate Class Cast Error | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Alessandro Carraro <carraro.alessandro> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED INVALID | QA Contact: | |
| Severity: | major | ||
| Priority: | P3 | CC: | sebastian.zarnekow, sven.efftinge |
| Version: | unspecified | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | M7 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
|
Description
Alessandro Carraro
The following is perfectly valid Java 1.5 code: int i = 1; Object o = (Object)i; This is valid, too: char c1 = 'a'; char c2 = 'b'; ObjectExtensions.operator_equals((Object)c1, (Object)c2); Since Xbase does not support character literals, an equals comparison of a char against a string(literal) will always be false. We could add special equal semantics for chars and strings but it would be have baked. I'm inclined to close this one as 'works for me'. Did I miss your point? (In reply to comment #0) > assuming charProperty is a char property, the following expression generate an > error in the generated class: ... sounds like there used to be a problem with the generated code which we have fixed in the meantime. Do we want an extension operator_equals(Character, String) that would allow to write 'a'.charAt(0) == 'a' and expect 'true' as the result? (In reply to comment #3) > Do we want an extension operator_equals(Character, String) that would allow to > write 'a'.charAt(0) == 'a' > and expect 'true' as the result? No. We may inform the user somehow that this is probably not what he wanted to do. Some kind of runtime logging or even an exception could help. I think warning "boolean expression is always false" iff the == operator is bound to ObjectExtensions#operator_equals(Object, Object) would be nice. (In reply to comment #1) > The following is perfectly valid Java 1.5 code: > > int i = 1; > Object o = (Object)i; > > This is valid, too: > > char c1 = 'a'; > char c2 = 'b'; > ObjectExtensions.operator_equals((Object)c1, (Object)c2); I'm rather perplex: javac compiles without errors, but eclipse complains. I checked tree times my java error configuration, but could not find anything related to autoboxing except the entry in 'Potential Problems' that is marked as 'Ignore' I did not want to compare char to Strings (I agree the type should be the same for equality) and I did not know that that xbase do not support chars. What I was looking for was something able to evaluate 2 char Properties: expression <<a.charProperty == a.charProperty>> should be true even if xbase does not support char literals, imho Btw, I found that the problem remains with all the primitive values Please reopen if I missed something. (In reply to comment #6) > (In reply to comment #1) > > The following is perfectly valid Java 1.5 code: > > > > int i = 1; > > Object o = (Object)i; > > > > This is valid, too: > > > > char c1 = 'a'; > > char c2 = 'b'; > > ObjectExtensions.operator_equals((Object)c1, (Object)c2); > > I'm rather perplex: javac compiles without errors, but eclipse complains. I > checked tree times my java error configuration, but could not find anything > related to autoboxing except the entry in 'Potential Problems' that is marked > as 'Ignore' > > I did not want to compare char to Strings (I agree the type should be the same > for equality) and I did not know that that xbase do not support chars. What I > was looking for was something able to evaluate 2 char Properties: > expression <<a.charProperty == a.charProperty>> should be true even if xbase > does not support char literals, imho > > Btw, I found that the problem remains with all the primitive values Sorry, I missed your last comment. Are you sure that the compliance settings for the compiler and the used JVM is 1.5 or better? (In reply to comment #6) > expression <<a.charProperty == a.charProperty>> should be true even if xbase > does not support char literals, imho It does evaluate to true. Aaargh! Sorry to everyone I made one of the biggest mistakes of my career! Please feel free to mark this bug as invalid and put a note to not respond ever again to me :( I feel so guilty! The problem was that my template name was stupidly 'Object' (historical reasons... I know it is a really meaningless name). So when you cast something to 'Object' it is not casting to java.lang.Object, but to tests.test1.Object |