Skip to content

Commit 604ce8c

Browse files
committed
tests: add a test for type inference involving sink
The existing `tsink_in_array.nim` test is merged into the new test.
1 parent 7f37955 commit 604ce8c

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

tests/lang_types/array/tsink_in_array.nim

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
discard """
2+
description: '''
3+
The `sink` parameter modifier is not part of the parameter expression's
4+
effective type.
5+
'''
6+
"""
7+
8+
proc test(param: sink int8) =
9+
# test let/var
10+
let a = param
11+
var b = param
12+
# no need to typeof-test `a` and `b`, since even if `a` and `b` were
13+
# inferred as `sink`-modified, `typeof` would drop the type
14+
15+
# test aggregate/composite type introduction
16+
let tup = (param, param)
17+
let named = (a: param, b: param)
18+
let arr = [param]
19+
let se = {param}
20+
21+
# test 'typeof'
22+
var x: (typeof(param),)
23+
24+
doAssert $typeof(tup) == "(int8, int8)"
25+
doAssert $typeof(named) == "tuple[a: int8, b: int8]"
26+
doAssert $typeof(arr) == "array[0..0, int8]"
27+
doAssert $typeof(se) == "set[int8]"
28+
doAssert $typeof(x) == "(int8,)"
29+
30+
test(1)
31+
32+
# test parameter type inference from default value expression
33+
proc param_test(x: sink int, y = x) =
34+
discard
35+
36+
doAssert $typeof(param_test) == "proc (x: sink int, y: int){.noSideEffect, gcsafe, locks: 0.}"

0 commit comments

Comments
 (0)