Skip to content
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

fix nil literal giving itself type untyped/typed [backport] #24165

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Sep 23, 2024

fixes #24164, regression from #20091

The expression nil as the default value of template parameter x: untyped is typechecked with expected type untyped since #20091. The expected type is checked if it matches the nil literal with a match better than a subtype match, and the type is set to it if it does. However untyped matches with a generic match which is better, so the nil literal has type untyped. This breaks type matching for the literal. So if the expected type is untyped or typed, it is now ignored and the nil literal just has the nil type.

@metagn metagn changed the title fix nil literal giving itself type untyped/typed fix nil literal giving itself type untyped/typed [backport:2.0] Sep 23, 2024
@metagn metagn changed the title fix nil literal giving itself type untyped/typed [backport:2.0] fix nil literal giving itself type untyped/typed [backport] Sep 23, 2024
@Araq Araq added the merge_when_passes_CI mergeable once green label Sep 23, 2024
@metagn metagn merged commit b9de2bb into nim-lang:devel Sep 23, 2024
19 checks passed
@metagn
Copy link
Collaborator Author

metagn commented Sep 23, 2024

@narimiran This can be backported as well for status-im/nim-eth#730 and status-im/nim-confutils#105

Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from b9de2bb

Hint: mm: orc; opt: speed; options: -d:release
174468 lines; 8.276s; 654.512MiB peakmem

narimiran pushed a commit that referenced this pull request Sep 23, 2024
…4165)

fixes #24164, regression from #20091

The expression `nil` as the default value of template parameter `x:
untyped` is typechecked with expected type `untyped` since #20091. The
expected type is checked if it matches the `nil` literal with a match
better than a subtype match, and the type is set to it if it does.
However `untyped` matches with a generic match which is better, so the
`nil` literal has type `untyped`. This breaks type matching for the
literal. So if the expected type is `untyped` or `typed`, it is now
ignored and the `nil` literal just has the `nil` type.

(cherry picked from commit b9de2bb)
@tersec
Copy link
Contributor

tersec commented Sep 23, 2024

@narimiran This can be backported as well for status-im/nim-eth#730 and status-im/nim-confutils#105

These are still failing on version-2-2 for the same reason.

@narimiran
Copy link
Member

These are still failing on version-2-2 for the same reason.

I've now merged devel into version-2-2. Shouldn't be happening anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge_when_passes_CI mergeable once green
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template param with default value nil and type untyped keeps the type untyped
4 participants