-
Notifications
You must be signed in to change notification settings - Fork 3
Fix mapping of type for null literals
#15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The `TypeInfo` for a `null` literal is expected to have a `null` `Type` property value.
| { | ||
| var o = (J.VariableDeclarations)((J.ClassDeclaration)cu.Members[0]).Body.Statements[0]; | ||
| o.Should().NotBeNull(); | ||
| var nullLiteral = (J.Literal)o.Variables[0].Initializer!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@macsux Requiring this explicit J.Literal cast here feels strange to me as a Java developer, as I would instead have expected the Type property declared in Expression here to be dynamically dispatched. I assume we implemented this in a non-idiomatic way in C#.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you would expect that. Initializer is of type Expression, so left side assignment would implicity be of same type. I can't imagine java would do something different, as it has no knowledge you're trying to use a derived, implementing class J.Literal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@macsux What you are saying is correct, but as I explained I only do the cast here, so that the Type property I reference on the next line will be resolved against J.Literal.Type and not Expression.Type, because the latter will in C# not do a polymorphic dispatch because of how default interface methods work in C#. In Java I can define a default method on any interface and it will always do a polymorphic dispatch to an override in an implementing class. Do you see what I mean?
| { | ||
| var o = (J.VariableDeclarations)((J.ClassDeclaration)cu.Members[0]).Body.Statements[0]; | ||
| o.Should().NotBeNull(); | ||
| var nullLiteral = (J.Literal)o.Variables[0].Initializer!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you would expect that. Initializer is of type Expression, so left side assignment would implicity be of same type. I can't imagine java would do something different, as it has no knowledge you're trying to use a derived, implementing class J.Literal.
The
TypeInfofor anullliteral is expected to have anullTypeproperty value.