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

Template param with default value nil and type untyped keeps the type untyped #24164

Closed
metagn opened this issue Sep 23, 2024 · 0 comments · Fixed by #24165
Closed

Template param with default value nil and type untyped keeps the type untyped #24164

metagn opened this issue Sep 23, 2024 · 0 comments · Fixed by #24165
Assignees

Comments

@metagn
Copy link
Collaborator

metagn commented Sep 23, 2024

Description

proc foo(x: proc ()) = x()

template bar(x: untyped = nil) =
  foo(x)

bar()

Nim Version

6f6e34e, 2.0

Current Output

Error: type mismatch: got <untyped>
but expected one of:
proc foo(x: proc ())
  first type mismatch at position: 1
  required type for x: proc (){.closure.}
  but expression 'nil' is of type: untyped

expression: foo(nil)

Expected Output

compiles

Known Workarounds

No response

Additional Information

No response

@metagn metagn self-assigned this Sep 23, 2024
metagn added a commit to metagn/Nim that referenced this issue Sep 23, 2024
@metagn metagn closed this as completed in b9de2bb Sep 23, 2024
narimiran pushed a commit that referenced this issue 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)
@metagn metagn mentioned this issue Oct 9, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant