4a915d897ac0 — Leonard Ritter 20 days ago
* `fn...`/`inline...` no trailing comma necessary for single argument anymore
2 files changed, 41 insertions(+), 18 deletions(-)

M lib/scopes/core.sc
M testing/test_overload.sc
M lib/scopes/core.sc +31 -8
@@ 6253,14 6253,37 @@ sugar fn... (name...)
                         break
                             sc_argument_list_join_values outargs
                                 \ tmpl atypes `(make-defaults atypes defaults)
-                    case ((arg as Symbol) ': rest...)
-                        hide-traceback;
-                        error@ ('anchor condv) "while parsing pattern"
-                            "single typed parameter definition is missing trailing comma or semicolon"
-                    case ((arg as Symbol) '= rest...)
-                        hide-traceback;
-                        error@ ('anchor condv) "while parsing pattern"
-                            "single default parameter definition is missing trailing comma or semicolon"
+                    case ((arg as Symbol) '= def)
+                        if ('variadic? arg)
+                            error "variadic parameter can not have default value"
+                        let param = (sc_parameter_new arg)
+                        sc_template_append_parameter tmpl param
+                        let def = (sc_expand def '() sugar-scope)
+                        repeat '()
+                            sc_argument_list_join_values types Unknown
+                            sc_argument_list_join_values defaults def
+                            'bind scope arg param
+                    case ((arg as Symbol) ': T '= def)
+                        if ('variadic? arg)
+                            error "a typed parameter can't be variadic"
+                        let T = (sc_expand T '() sugar-scope)
+                        let param = (sc_parameter_new arg)
+                        sc_template_append_parameter tmpl param
+                        let def = (sc_expand def '() sugar-scope)
+                        repeat '()
+                            sc_argument_list_join_values types T
+                            sc_argument_list_join_values defaults def
+                            'bind scope arg param
+                    case ((arg as Symbol) ': T)
+                        if ('variadic? arg)
+                            error "a typed parameter can't be variadic"
+                        let T = (sc_expand T '() sugar-scope)
+                        let param = (sc_parameter_new arg)
+                        sc_template_append_parameter tmpl param
+                        repeat '()
+                            sc_argument_list_join_values types T
+                            sc_argument_list_join_values defaults nodefault
+                            'bind scope arg param
                     case ((arg as Symbol) rest...)
                         if ('variadic? arg)
                             if (not (empty? rest...))

          
M testing/test_overload.sc +10 -10
@@ 8,7 8,7 @@ let testf = (static-typify testf i32 i32
 
 # define overloaded function and expand existing testf
 fn... testf
-case (a : i32,)
+case (a : i32)
     testf a a
 # try the template last
 case using testf

          
@@ 87,12 87,12 @@ inline ArrayPattern (element-type)
             inline (self) self
 
 fn... test5
-case (a : (ArrayPattern i32),) 3
-case (a : (ArrayPattern f32),) 4
-case (a : &i32,) true
-case (a : i32,) false
-case (a : &real,) 1
-case (a : real,) 2
+case (a : (ArrayPattern i32)) 3
+case (a : (ArrayPattern f32)) 4
+case (a : &i32) true
+case (a : i32) false
+case (a : &real) 1
+case (a : real) 2
 
 test ((test5 1) == false)
 local y = 2

          
@@ 118,9 118,9 @@ do
 
     # typematcher
     fn... test7
-    case (a : (typematch T < integer),) 1
-    case (a : (typematch T < real),) 2
-    case (a : (typematch (storageof T) < real),) 3
+    case (a : (typematch T < integer)) 1
+    case (a : (typematch T < real)) 2
+    case (a : (typematch (storageof T) < real)) 3
     #case (a : (typematch T in (tupleof M L)),) 3
 
     test ((test7 1) == 1)