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

Generic type constraints not respected with generic function #23020

Closed
tersec opened this issue Dec 2, 2023 · 3 comments · Fixed by #24525
Closed

Generic type constraints not respected with generic function #23020

tersec opened this issue Dec 2, 2023 · 3 comments · Fixed by #24525

Comments

@tersec
Copy link
Contributor

tersec commented Dec 2, 2023

Description

proc n[T: bool](k: int | int) =
  #static:
  #  doAssert T is bool
  #  doAssert T isnot int

  # And runtime
  block:
    doAssert T is bool
    doAssert T isnot int

n[int](0)

Nim Version

Nim Compiler Version 1.6.17 [Linux: amd64]
Compiled at 2023-12-02
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 2e87171e14d4f28012c53fdc54919b5491f328be
active boot switches: -d:release
Nim Compiler Version 2.0.1 [Linux: amd64]
Compiled at 2023-12-02
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 3ab6012c81a6007fc108950de6a0ae4bfc4252bd
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-12-02
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: a25843cf8010db92de4e95e734e11208f36fea86
active boot switches: -d:release

Current Output

When using runtime asserts:
/tmp/m.nim(11)           m
/tmp/m.nim(8)            n
NimDevel/lib/std/assertions.nim(41) failedAssertImpl
NimDevel/lib/std/assertions.nim(36) raiseAssert
NimDevel/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: /tmp/m.nim(8, 5) `T is bool`  [AssertionDefect]

When using static asserts:
stack trace: (most recent call last)
/tmp/m.nim(3, 11)        n
NimDevel/lib/std/assertions.nim(41, 14) failedAssertImpl
NimDevel/lib/std/assertions.nim(36, 13) raiseAssert
NimDevel/lib/system/fatal.nim(53, 5) sysFatal
/tmp/m.nim(11, 7) template/generic instantiation of `n` from here
NimDevel/lib/system/fatal.nim(53, 5) Error: unhandled exception: /tmp/m.nim(3, 5) `T is bool`  [AssertionDefect]

Expected Output

/tmp/m.nim(11, 1) Error: cannot instantiate: 'n[int]'

Possible Solution

No response

Additional Information

No response

@tersec
Copy link
Contributor Author

tersec commented May 8, 2024

@bung87 this is not an Error Messages problem. It's broken type-checking

@tersec
Copy link
Contributor Author

tersec commented May 8, 2024

The error message is just the way to demonstrate it

@metagn
Copy link
Collaborator

metagn commented Sep 18, 2024

Since #24010, the overload no longer matches

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

Successfully merging a pull request may close this issue.

3 participants