Skip to content

Conversation

@knutwannheden
Copy link
Contributor

The TypeInfo for a null literal is expected to have a null Type property value.

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!;
Copy link
Contributor Author

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#.

Copy link
Collaborator

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.

Copy link
Contributor Author

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!;
Copy link
Collaborator

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.

@macsux macsux merged commit 5b4f4a9 into main Oct 7, 2024
@macsux macsux deleted the map-null-literal-type branch October 7, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants