nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.58k stars 1.47k forks source link

Using `static T` type alias twice in routine def doesn't accept arguments #16187

Open metagn opened 3 years ago

metagn commented 3 years ago

Example

type Foo = static int

proc bar(a, b: Foo) = echo a + b # doesn't matter if a: Foo, b: Foo or a, b: Foo

bar(1, 2)

Current Output

(5, 4) Error: type mismatch: got <int literal(1), int literal(2)>
but expected one of: 
proc bar(a, b: Foo)
  first type mismatch at position: 2
  required type for b: Foo
  but expression '2' is of type: int literal(2)

expression: bar(1, 2)

Expected Output

3

Additional Information

$ nim -v
Nim Compiler Version 1.4.0
metagn commented 3 years ago

Same goes for iterator:

type Foo = static int

iterator bar(a, b: Foo): int =
  yield a
  yield b

for x in bar(1, 2):
  echo x

Fails with a similar error

Edit: Goes for all routines actually

cooldome commented 3 years ago

Interesting that this compiles:

type Foo = static int

template bar(a: Foo; b: Foo) = echo a + b # doesn't matter if a: Foo, b: Foo or a, b: Foo

bar(1, 1)