fix #12864 static params were mutating arg types during sigmatch; fix #12713 ; refs #13529 (#13976)

* fix #12864 static params were mutating arg types during sigmatch

* fix test

* fix StaticParam

* also fixes #12713; added test case
This commit is contained in:
Timothee Cour 2020-04-14 06:00:02 -07:00 • committed by GitHub
commit 10eabec6d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 6 deletions

View file

@ -170,3 +170,49 @@ var
s: StringValue16
echo s
block: #13529
block:
type Foo[T: static type] = object
var foo: Foo["test"]
doAssert $foo == "()"
doAssert foo.T is string
static: doAssert foo.T == "test"
doAssert not compiles(
block:
type Foo2[T: static type] = object
x: T)
block:
type Foo[T: static[float]] = object
var foo: Foo[1.2]
doAssert $foo == "()"
doAssert foo.T == 1.2
block: # routines also work
proc fun(a: static) = (const a2 = a)
fun(1)
fun(1.2)
block: # routines also work
proc fun(a: static type) = (const a2 = a)
fun(1)
fun(1.2)
block: # this also works
proc fun[T](a: static[T]) = (const a2 = a)
fun(1)
fun(1.2)
block: # #12713
block:
type Cell = object
c: int
proc test(c: static string) = discard #Remove this and it compiles
proc test(c: Cell) = discard
test Cell(c: 0)
block:
type Cell = object
c: int
proc test(c: static string) = discard #Remove this and it compiles
proc test(c: Cell) = discard
test Cell()