Skip to content

Commit 66ac669

Browse files
LingDong-Lingdong Huang
authored andcommitted
prevent crash when scope deplete in typechecker
1 parent bae0a65 commit 66ac669

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/typecheck.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ function typecheck(
126126

127127
return undefined;
128128
}
129-
function checkscopethis(name) {
129+
function checkscopethis(name, pos) {
130+
assert(
131+
"Scope stack depleted, possibly due to extraneous end-block statement.",
132+
pos,
133+
scope.length
134+
);
130135
return checkscopei(scope.length - 1, name);
131136
}
132137

@@ -267,7 +272,7 @@ function typecheck(
267272
assert(
268273
`[Type] Variable '${a.names[j]}' redeclared in the same scope`,
269274
a.pos,
270-
!checkscopethis(a.names[j])
275+
!checkscopethis(a.names[j], a.pos)
271276
);
272277

273278
scope[scope.length - 1][a.names[j]] = inittype(a.type);
@@ -468,6 +473,7 @@ function typecheck(
468473
ty.type = "obj";
469474
ty.fields = {};
470475
ty.fields[a.value[1].slice(1, -1)] = inittype("any");
476+
ty.isarg = true;
471477
}
472478
assert(
473479
`[Type] Property ${a.value[1]} does not exist in obj ${printType(

tools/test_parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ function runAll(lang, skips = []) {
5454

5555
// runExample("js", "quicksort");
5656
// runExample("js", "../lib/js/畫譜");
57-
// runExample("js", "../lib/列經");
57+
runExample("js", "../lib/曆法");
5858
// runAll("js", ["quine", "quine2", "tree", "tree2", "try"]);
5959
// runAll("js", ["quine"]);
6060

61-
runExample("js", "../../../Downloads/local_test");
61+
// runExample("js", "../../../Downloads/local_test");
6262
// runExample("py", "draw_heart");

0 commit comments

Comments
 (0)