diff options
-rw-r--r-- | compiler/sigmatch.nim | 3 | ||||
-rw-r--r-- | tests/generics/tcannot_pass_empty_seq_to_generic.nim | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index e44cd7049..266236bf4 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -242,6 +242,9 @@ proc concreteType(c: TCandidate, t: PType): PType = addSonSkipIntLit(result, t.sons[1]) # XXX: semantic checking for the type? of tyNil: result = nil # what should it be? + of tySequence, tySet: + if t.sons[0].kind == tyEmpty: result = nil + else: result = t of tyGenericParam, tyAnything: result = t while true: diff --git a/tests/generics/tcannot_pass_empty_seq_to_generic.nim b/tests/generics/tcannot_pass_empty_seq_to_generic.nim new file mode 100644 index 000000000..5f0363af8 --- /dev/null +++ b/tests/generics/tcannot_pass_empty_seq_to_generic.nim @@ -0,0 +1,17 @@ +discard """ + errormsg: "type mismatch: got (seq[empty])" + line: 16 +""" + +# bug #836 + +type + TOption*[T] = object + case FIsSome: bool + of false: nil + of true: FData: T + +proc some*[T](value: T): TOption[T] = TOption[T](FIsSome: true, FData: value) + +echo some(@[]).FIsSome + |