Skip to content

Commit 41f82af

Browse files
LingDong-Lingdong Huang
authored andcommitted
fix obj in args (real)
1 parent db9597c commit 41f82af

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/typecheck.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function printType(t, n = 0, d = 0) {
2929
s += k + " : (" + printType(t.fields[k], n + m, d + 1) + "), ";
3030
m++;
3131
}
32-
s = s.slice(0, -2) + " }";
32+
if (s.length > 2) {
33+
s = s.slice(0, -2);
34+
}
35+
s += " }";
3336
return s;
3437
}
3538
return t.type;
@@ -163,6 +166,13 @@ function typecheck(
163166
assert(`[Type] Expecting value, found '${tok[0]}'`, tok[2], false);
164167
}
165168

169+
function objfield(t, x) {
170+
if (t.isarg) {
171+
t.fields[x] = inittype("any");
172+
}
173+
return t.fields[x];
174+
}
175+
166176
function scopepush(pos) {
167177
scope.push({});
168178
scopestarts.push(pos);
@@ -274,6 +284,9 @@ function typecheck(
274284
let ptr = scope[scope.length - 1][funstack[funstack.length - 1]];
275285
for (let j = 0; j < a.arity; j++) {
276286
ptr.in = inittype(a.args[j].type);
287+
if (a.args[j].type == "obj") {
288+
ptr.in.isarg = true;
289+
}
277290
ptr.in.name = a.args[j].name;
278291
if (j != a.arity - 1) {
279292
ptr.out = inittype("fun");
@@ -461,7 +474,7 @@ function typecheck(
461474
ty
462475
)}`,
463476
a.pos,
464-
ty.fields[a.value[1].slice(1, -1)]
477+
objfield(ty, a.value[1].slice(1, -1))
465478
);
466479

467480
strayvar.push(Object.assign({}, ty.fields[a.value[1].slice(1, -1)]));
@@ -553,7 +566,7 @@ function typecheck(
553566
if (tl.type == "any") {
554567
tlv = inittype("any");
555568
} else {
556-
tlv = tl.fields[a.lhssubs[1].slice(1, -1)];
569+
tlv = objfield(tl, a.lhssubs[1].slice(1, -1));
557570
}
558571
} else {
559572
typeassert(
@@ -592,7 +605,7 @@ function typecheck(
592605
if (tr.type == "any") {
593606
trv = inittype("any");
594607
} else {
595-
trv = tr.fields[a.rhssubs[1].slice(1, -1)];
608+
trv = objfield(tr, a.rhssubs[1].slice(1, -1));
596609
}
597610
} else {
598611
typeassert(

0 commit comments

Comments
 (0)