-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
Example
1
type Test = object
x: int
echo Test(42)2
type Test[T] = object
x: T
echo Test(42)3
type Test[T] = object
x: T
echo Test(x: 42)Current Output
1
Error: type mismatch: got 'int literal(42)' for '42' but expected 'Test = object'
2
Error: type mismatch: got 'int literal(42)' for '42' but expected 'Test = CompositeTypeClass'
3
Error: object constructor needs an object type
Expected Output
1
Error: expected object constructor
2
Error: expected object constructor
3
No error, T should be inferred to int. The same works with procs:
proc test[T](x: T): T = x
echo test(42) # compilesAdditional Information
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-04-19
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 3b80f0dc8ef2bc9d2a981a7c92a6355dfc72b7ef
active boot switches: -d:release