summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-11-19 23:40:26 +0100
committerAraq <rumpf_a@web.de>2014-11-19 23:40:26 +0100
commitabb2c210474b383045dd309dad6731009f07f7f9 (patch)
treed13809f074b780eaaed2ef3cb1ae487ef26bae1c
parent32ec5af60a5d89fca314c3b432d225f1e248953f (diff)
downloadNim-abb2c210474b383045dd309dad6731009f07f7f9.tar.gz
fixes #836
-rw-r--r--compiler/sigmatch.nim3
-rw-r--r--tests/generics/tcannot_pass_empty_seq_to_generic.nim17
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
+