bdeb83d2ca71 — Leonard Ritter 2 months ago
* fixed `String <constant>` matching the `string` constructor
* `__typematch` is tried again with qualified arguments if the unqualified query fails
3 files changed, 18 insertions(+), 4 deletions(-)

M lib/scopes/String.sc
M lib/scopes/core.sc
M testing/test_object.sc
M lib/scopes/String.sc +8 -2
@@ 11,8 11,6 @@ 
 
 using import struct
 
-let &chararray = (& (array char))
-
 # declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
                                         i64 <len>, i1 <isvolatile>)
 let llvm.memcpy.p0i8.p0i8.i64 =

          
@@ 160,6 158,14 @@ inline &chararray? (T)
         (unqualified T) < array
         (elementof T) == char
 
+# dispatch helper
+typedef &chararray
+    inline __typematch (paramT argT)
+        &chararray? argT
+    # simple passthru, since __typematch has already been used
+    inline __rimply (argT clsT)
+        inline (self) self
+
 inline string-binary-op (f superf)
     @@ memo
     inline (cls T)

          
M lib/scopes/core.sc +8 -2
@@ 6583,16 6583,22 @@ fn nodefault? (x)
 fn spice-typematch? (qparamT qargT arg-constant?)
     let argT = ('strip-qualifiers qargT)
     let paramT = ('strip-qualifiers qparamT)
+    inline match-param-ref? ()
+        not (('refer? qparamT) & (not ('refer? qargT)))
     assert (paramT != Variadic)
     if (paramT == Unknown)
         return true
     elseif (argT <= paramT)
-        return (not (('refer? qparamT) & (not ('refer? qargT))))
+        return (match-param-ref?)
     try
         let matchfunc = ('@ paramT '__typematch)
         let result = (sc_prove `(matchfunc paramT argT))
+        if ((result as bool) and (match-param-ref?))
+            return true
+        # try fully qualified
+        let result = (sc_prove `(matchfunc qparamT qargT))
         if (result as bool)
-            return (not (('refer? qparamT) & (not ('refer? qargT))))
+            return true
         else
             return false
     else;

          
M testing/test_object.sc +2 -0
@@ 2,6 2,7 @@ 
 #let x = (unconst true)
 #global y = x
 
+using import String
 using import C.stdio
 
 let i32x10 = (array i32 10)

          
@@ 33,6 34,7 @@ print "y=" (deref y)
 fn main (argc argv)
     x @ 3 = 6
     #y = 7
+    local s = (String "banana")
     printf "hello world %i %i\n"
         deref (x @ 3)
         deref y