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

Procedure with a static range generic parameter cause type mismatch #23343

Open
demotomohiro opened this issue Feb 22, 2024 · 1 comment
Open

Comments

@demotomohiro
Copy link
Contributor

Description

When I define a generic type and a proc with a static range generic parameter and call it,
it always cause type mismatch compile error.

type
  Foo[N: static int] = object
    x: array[N, int]
  Bar[N: static range[1 .. 8]] = object
    x: array[N, int]

# I can call Procedures with static int generic parameter
proc testFoo[N: static int](x: Foo[N]) =
  discard

testFoo(Foo[1]())

proc testBar[N: static int](x: Bar[N]) =
  discard

testBar(Bar[1]())

proc testFooRange[N: static range[1 .. 8]](x: Foo[N]) =
  discard

# Expression: testFooRange(Foo[1]())
#   [1] Foo[1](): Foo[1]
#
# Expected one of (first mismatch at [position]):
# [1] proc testFooRange[N: static range[1 .. 8]](x: Foo[N])
testFooRange(Foo[1]())

proc testBarRange[N: static range[1 .. 8]](x: Bar[N]) =
  discard

# Error: type mismatch
# Expression: testBarRange(Bar[1]())
#   [1] Bar[1](): Bar[1]
#
# Expected one of (first mismatch at [position]):
# [1] proc testBarRange[N: static range[1 .. 8]](x: Bar[N])
testBarRange(Bar[1]())

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-02-22
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 59c6500
active boot switches: -d:release

Current Output

testrange.nim(26, 13) Error: type mismatch
Expression: testFooRange(Foo[1]())
  [1] Foo[1](): Foo[1]

Expected one of (first mismatch at [position]):
[1] proc testFooRange[N: static range[1 .. 8]](x: Foo[N])

Expected Output

Above example code is compiled without errors.

Possible Solution

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Sep 18, 2024

Kind of related to #4858 etc, Nim accepts that 1 matches range[1..8] so it passes it directly as a static type, but its actual type remains as int. Passing range[1..8](1) instead works.

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

No branches or pull requests

2 participants