@@ -29,7 +29,10 @@ function printType(t, n = 0, d = 0) {
29
29
s += k + " : (" + printType ( t . fields [ k ] , n + m , d + 1 ) + "), " ;
30
30
m ++ ;
31
31
}
32
- s = s . slice ( 0 , - 2 ) + " }" ;
32
+ if ( s . length > 2 ) {
33
+ s = s . slice ( 0 , - 2 ) ;
34
+ }
35
+ s += " }" ;
33
36
return s ;
34
37
}
35
38
return t . type ;
@@ -163,6 +166,13 @@ function typecheck(
163
166
assert ( `[Type] Expecting value, found '${ tok [ 0 ] } '` , tok [ 2 ] , false ) ;
164
167
}
165
168
169
+ function objfield ( t , x ) {
170
+ if ( t . isarg ) {
171
+ t . fields [ x ] = inittype ( "any" ) ;
172
+ }
173
+ return t . fields [ x ] ;
174
+ }
175
+
166
176
function scopepush ( pos ) {
167
177
scope . push ( { } ) ;
168
178
scopestarts . push ( pos ) ;
@@ -274,6 +284,9 @@ function typecheck(
274
284
let ptr = scope [ scope . length - 1 ] [ funstack [ funstack . length - 1 ] ] ;
275
285
for ( let j = 0 ; j < a . arity ; j ++ ) {
276
286
ptr . in = inittype ( a . args [ j ] . type ) ;
287
+ if ( a . args [ j ] . type == "obj" ) {
288
+ ptr . in . isarg = true ;
289
+ }
277
290
ptr . in . name = a . args [ j ] . name ;
278
291
if ( j != a . arity - 1 ) {
279
292
ptr . out = inittype ( "fun" ) ;
@@ -461,7 +474,7 @@ function typecheck(
461
474
ty
462
475
) } `,
463
476
a . pos ,
464
- ty . fields [ a . value [ 1 ] . slice ( 1 , - 1 ) ]
477
+ objfield ( ty , a . value [ 1 ] . slice ( 1 , - 1 ) )
465
478
) ;
466
479
467
480
strayvar . push ( Object . assign ( { } , ty . fields [ a . value [ 1 ] . slice ( 1 , - 1 ) ] ) ) ;
@@ -553,7 +566,7 @@ function typecheck(
553
566
if ( tl . type == "any" ) {
554
567
tlv = inittype ( "any" ) ;
555
568
} else {
556
- tlv = tl . fields [ a . lhssubs [ 1 ] . slice ( 1 , - 1 ) ] ;
569
+ tlv = objfield ( tl , a . lhssubs [ 1 ] . slice ( 1 , - 1 ) ) ;
557
570
}
558
571
} else {
559
572
typeassert (
@@ -592,7 +605,7 @@ function typecheck(
592
605
if ( tr . type == "any" ) {
593
606
trv = inittype ( "any" ) ;
594
607
} else {
595
- trv = tr . fields [ a . rhssubs [ 1 ] . slice ( 1 , - 1 ) ] ;
608
+ trv = objfield ( tr , a . rhssubs [ 1 ] . slice ( 1 , - 1 ) ) ;
596
609
}
597
610
} else {
598
611
typeassert (
0 commit comments