mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
closes #4774, closes #7385, closes #10019, closes #12405, closes #12732, closes #13270, closes #13799, closes #15247, closes #16128, closes #16175, closes #16774, closes #17527, closes #20880, closes #21346
56 lines
1.9 KiB
Nim
56 lines
1.9 KiB
Nim
block: # issue #16376
|
|
type
|
|
Matrix[T] = object
|
|
data: T
|
|
proc randMatrix[T](m, n: int, max: T): Matrix[T] = discard
|
|
proc randMatrix[T](m, n: int, x: Slice[T]): Matrix[T] = discard
|
|
template randMatrix[T](m, n: int): Matrix[T] = randMatrix[T](m, n, T(1.0))
|
|
let B = randMatrix[float32](20, 10)
|
|
|
|
block: # different generic param counts
|
|
type
|
|
Matrix[T] = object
|
|
data: T
|
|
proc randMatrix[T](m: T, n: T): Matrix[T] = Matrix[T](data: T(1.0))
|
|
proc randMatrix[T; U: not T](m: T, n: U): (Matrix[T], U) = (Matrix[T](data: T(1.0)), default(U))
|
|
let b = randMatrix[float32](20, 10)
|
|
doAssert b == Matrix[float32](data: 1.0)
|
|
|
|
block: # above for templates
|
|
type
|
|
Matrix[T] = object
|
|
data: T
|
|
template randMatrix[T](m: T, n: T): Matrix[T] = Matrix[T](data: T(1.0))
|
|
template randMatrix[T; U: not T](m: T, n: U): (Matrix[T], U) = (Matrix[T](data: T(1.0)), default(U))
|
|
let b = randMatrix[float32](20, 10)
|
|
doAssert b == Matrix[float32](data: 1.0)
|
|
|
|
block: # sigmatch can't handle this without pre-instantiating the type:
|
|
# minimized from numericalnim
|
|
type Foo[T] = proc (x: T)
|
|
proc foo[T](x: T) = discard
|
|
proc bar[T](f: Foo[T]) = discard
|
|
bar[int](foo)
|
|
|
|
block: # ditto but may be wrong minimization
|
|
# minimized from measuremancer
|
|
type Foo[T] = object
|
|
proc foo[T](): Foo[T] = Foo[T]()
|
|
# this is the actual issue but there are other instantiation problems
|
|
proc bar[T](x = foo[T]()) = discard
|
|
bar[int](Foo[int]())
|
|
bar[int]()
|
|
# alternative version, also causes instantiation issue
|
|
proc baz[T](x: typeof(foo[T]())) = discard
|
|
baz[int](Foo[int]())
|
|
|
|
block: # issue #21346
|
|
type K[T] = object
|
|
template s[T](x: int) = doAssert T is K[K[int]]
|
|
proc b1(n: bool | bool) = s[K[K[int]]](3)
|
|
proc b2(n: bool) = s[K[K[int]]](3)
|
|
template b3(n: bool) = s[K[K[int]]](3)
|
|
b1(false) # Error: cannot instantiate K; got: <T> but expected: <T>
|
|
b2(false) # Builds, on its own
|
|
b3(false)
|