summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2017-11-18 08:21:37 +0000
committerAndreas Rumpf <rumpf_a@web.de>2017-11-18 09:21:37 +0100
commit8443e3f6bee2596b042fcb991d70496efa45d9dc (patch)
treef2c81578fa4ff55f886d4cc4ffb93e4153181e0d
parent416aa921fa0cfefda5f3ee30329c8378f2e2008a (diff)
downloadNim-8443e3f6bee2596b042fcb991d70496efa45d9dc.tar.gz
Fix compiler crash (#6773) (#6774)
-rw-r--r--compiler/sigmatch.nim2
-rw-r--r--tests/overload/tstatic_with_converter.nim47
2 files changed, 48 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 97b18306b..31714b7bf 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1613,7 +1613,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
           if not exprStructuralEquivalent(f.n, aOrig.n):
             result = isNone
         if result != isNone: put(c, f, aOrig)
-      elif aOrig.n != nil:
+      elif aOrig.n != nil and aOrig.n.typ != nil:
         result = typeRel(c, f.lastSon, aOrig.n.typ)
         if result != isNone:
           var boundType = newTypeWithSons(c.c, tyStatic, @[aOrig.n.typ])
diff --git a/tests/overload/tstatic_with_converter.nim b/tests/overload/tstatic_with_converter.nim
new file mode 100644
index 000000000..2871744eb
--- /dev/null
+++ b/tests/overload/tstatic_with_converter.nim
@@ -0,0 +1,47 @@
+discard """
+output: '''
+9.0'''
+"""
+
+### bug #6773
+
+{.emit: """ /*INCLUDESECTION*/
+typedef double cimported;
+ 
+cimported set1_imported(double x) {
+  return x;
+}
+ 
+"""}
+ 
+type vfloat{.importc: "cimported".} = object
+ 
+proc set1(a: float): vfloat {.importc: "set1_imported".}
+ 
+converter scalar_to_vector(x: float): vfloat =
+  set1(x)
+ 
+proc sqrt(x: vfloat): vfloat =
+  x
+ 
+proc pow(x, y: vfloat): vfloat =
+  y
+ 
+proc `^`(x: vfloat, exp: static[int]): vfloat =
+  when exp == 0:
+    1.0
+  else:
+    x
+ 
+proc `^`(x: vfloat, exp: static[float]): vfloat =
+  when exp == 0.5:
+    sqrt(x)
+  else:
+   pow(x, exp)
+ 
+proc `$`(x: vfloat): string =
+  let y = cast[ptr float](unsafeAddr x)
+  echo y[]
+ 
+let x = set1(9.0)
+echo x^0.5