Fix special 'null' cases when inferring array literals #1088
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the issues reported in #1083, except that it doesn't yet disallow inferring
null
tousize
if the contextual type is not a reference type as this would be a breaking change I'm not sure about yet.Referencing the snippets of the original issue:
This now compiles due to inferring logic skipping null literals, and applying the nullable flag afterwards.
This now produces an error because
null
has been skipped and the final element type isauto
. More of a side-effect that would play well with disallowingnull
in non-reference contexts, if we decide to go for that.This still compiles. While the
null
literal is skipped,i32
is not nullable so remainsi32
sonull
behaves like it's in ani32
context. In 32-bit, itsusize
type is implicitly convertible toi32
. Disallowingnull
, as mentioned above, would result in an error here.This now compiles since the inference logic has been moved to the resolver. Infers
i32[], i32[]
, theni32[][]
.