timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

type inference broken with @[] #401

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

type inference broken with @[]

Example

when true:
  proc fn[T](a: seq[T], b: openArray[T]) =
    echo a, ",", b
  fn(seq[int].default, [1,2]) # ok
  fn(@[0], [1,2]) # ok
  fn(@[], [1,2]) # error

Current Output

Error: type mismatch: got <seq[empty], array[0..1, int]>
but expected one of:
proc fn[T](a: seq[T]; b: openArray[T]) [proc declared in /Users/timothee/git_clone/nim/timn/tests/nim/all/t11395.nim(40, 8)]
  first type mismatch at position: 2
  required type for b: openArray[T] [openArray]
  but expression '[1, 2]' is of type: array[0..1, int] [array]

expression: fn(@[], [1, 2])
    fn(@[], [1,2])

Expected Output

works

Possible Solution

make type inference smarter when a type contains empty, delaying resolving until later arguments are seen

Additional Information

1.5.1 devel 6114df3c24e9c23bfbdbaa204bb100de9d170995

ringabout commented 3 years ago

Related: https://github.com/nim-lang/Nim/issues/15905