fez-lisp 1.6.69 → 1.6.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/check.js +60 -39
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -616,25 +616,23 @@ const resolveGetterRec = ([head, tail], env, times = 0) => {
|
|
616
616
|
if (GET_ARRAY_INFERENCE_SET.has(head[VALUE])) {
|
617
617
|
return resolveGetterRec(tail, env, ++times)
|
618
618
|
} else {
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
case WORD:
|
623
|
-
{
|
624
|
-
if (env[tail][STATS][TYPE_PROP][0] === UNKNOWN) return
|
625
|
-
const types = env[tail][STATS][TYPE_PROP][1].types
|
626
|
-
const sub = types.at(-1)
|
627
|
-
const type =
|
628
|
-
sub === ATOM || sub === NUMBER || sub === BOOLEAN
|
629
|
-
? ATOM
|
630
|
-
: sub === APPLY
|
631
|
-
? APPLY
|
632
|
-
: COLLECTION
|
633
|
-
const len = types.length ? types.length + 1 : times + 1
|
634
|
-
return [times, len, type, types]
|
635
|
-
}
|
636
|
-
break
|
619
|
+
if (Array.isArray(head)) {
|
620
|
+
tail = head[VALUE]
|
621
|
+
head = head[TYPE]
|
637
622
|
}
|
623
|
+
if (head !== WORD && head !== APPLY) return
|
624
|
+
const prop = head === WORD ? TYPE_PROP : RETURNS
|
625
|
+
if (!env[tail] || env[tail][STATS][prop][0] === UNKNOWN) return
|
626
|
+
const types = env[tail][STATS][prop][1].types
|
627
|
+
const sub = types.at(-1)
|
628
|
+
const type =
|
629
|
+
sub === ATOM || sub === NUMBER || sub === BOOLEAN
|
630
|
+
? ATOM
|
631
|
+
: sub === APPLY
|
632
|
+
? APPLY
|
633
|
+
: COLLECTION
|
634
|
+
const len = types.length ? types.length + 1 : times + 1
|
635
|
+
return [times, len, type, types]
|
638
636
|
}
|
639
637
|
}
|
640
638
|
const resolveGetter = ({ rem, prop, name, env, caller, exp }) => {
|
@@ -649,9 +647,9 @@ const resolveGetter = ({ rem, prop, name, env, caller, exp }) => {
|
|
649
647
|
const [times, level, type, types] = resolveGetterRec(rem, env)
|
650
648
|
if (times >= level)
|
651
649
|
throw new RangeError(
|
652
|
-
`(${caller}) is trying to access nested structure at level (${level}) which is deeper than it's (${
|
653
|
-
|
654
|
-
)}) (check #1003)`
|
650
|
+
`(${caller}) is trying to access nested structure at level (${level}) which is deeper than it's (${
|
651
|
+
times - 1
|
652
|
+
}) levels at (${stringifyArgs(exp)}) (check #1003)`
|
655
653
|
)
|
656
654
|
if (times === level - 1) {
|
657
655
|
setPropToType(env[name][STATS], prop, {
|
@@ -668,7 +666,6 @@ const resolveGetter = ({ rem, prop, name, env, caller, exp }) => {
|
|
668
666
|
}
|
669
667
|
return true
|
670
668
|
}
|
671
|
-
|
672
669
|
if (
|
673
670
|
getReturn(env[array[VALUE]][STATS]) === UNKNOWN ||
|
674
671
|
getReturn(env[array[VALUE]][STATS]) === ANY
|
@@ -970,8 +967,26 @@ const resolveReturnType = ({
|
|
970
967
|
break
|
971
968
|
default:
|
972
969
|
{
|
973
|
-
if (GET_ARRAY_INFERENCE_SET.has(returns[VALUE]))
|
974
|
-
resolveGetter({
|
970
|
+
if (GET_ARRAY_INFERENCE_SET.has(returns[VALUE])) {
|
971
|
+
resolveGetter({
|
972
|
+
rem,
|
973
|
+
prop,
|
974
|
+
name,
|
975
|
+
env,
|
976
|
+
caller: returns[VALUE],
|
977
|
+
exp
|
978
|
+
})
|
979
|
+
retry(env[name][STATS], exp, stack, () => {
|
980
|
+
resolveGetter({
|
981
|
+
rem,
|
982
|
+
prop,
|
983
|
+
name,
|
984
|
+
env,
|
985
|
+
caller: returns[VALUE],
|
986
|
+
exp
|
987
|
+
})
|
988
|
+
})
|
989
|
+
}
|
975
990
|
checkPredicateNameDeep(name, exp, exp.slice(1), returns)
|
976
991
|
// TODO: DRY
|
977
992
|
const index = env[name][STATS][ARGUMENTS]
|
@@ -1327,17 +1342,23 @@ export const typeCheck = (
|
|
1327
1342
|
// If current scope is root then these are user defined types
|
1328
1343
|
if (isLambda) {
|
1329
1344
|
const lambdaName = `${PLACEHOLDER}${name}`
|
1330
|
-
|
1331
|
-
[
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
env,
|
1337
|
-
scope
|
1338
|
-
)
|
1345
|
+
const fn = [
|
1346
|
+
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
1347
|
+
[WORD, lambdaName],
|
1348
|
+
exp.at(-1)
|
1349
|
+
]
|
1350
|
+
check(fn, env, scope)
|
1339
1351
|
const expected = env[name]
|
1340
1352
|
const actual = env[lambdaName]
|
1353
|
+
if (expected[ARG_COUNT] !== actual[ARG_COUNT]) {
|
1354
|
+
throw new RangeError(
|
1355
|
+
`Incorrect number of arguments for (${
|
1356
|
+
expected[STATS][SIGNATURE]
|
1357
|
+
}) Expected (${expected[ARG_COUNT]}) but got (${
|
1358
|
+
actual[ARG_COUNT]
|
1359
|
+
}) (${stringifyArgs(exp)}) (check #1004)`
|
1360
|
+
)
|
1361
|
+
}
|
1341
1362
|
const checkReturns = () => {
|
1342
1363
|
if (
|
1343
1364
|
!isUnknownReturn(actual[STATS]) &&
|
@@ -1382,9 +1403,9 @@ export const typeCheck = (
|
|
1382
1403
|
checkArgs()
|
1383
1404
|
// Check lambda body with defined types
|
1384
1405
|
const copy = Object.create(env)
|
1385
|
-
for (let i = 0; i <
|
1386
|
-
const A =
|
1387
|
-
const B =
|
1406
|
+
for (let i = 0; i < expected[STATS][ARGUMENTS].length; ++i) {
|
1407
|
+
const A = actual[STATS][ARGUMENTS][i]
|
1408
|
+
const B = expected[STATS][ARGUMENTS][i]
|
1388
1409
|
copy[A[STATS][SIGNATURE]] = {
|
1389
1410
|
[STATS]: {
|
1390
1411
|
[SIGNATURE]: A[STATS][SIGNATURE],
|
@@ -1394,12 +1415,12 @@ export const typeCheck = (
|
|
1394
1415
|
}
|
1395
1416
|
}
|
1396
1417
|
check(
|
1397
|
-
wrapInApplyLambda(
|
1418
|
+
wrapInApplyLambda(
|
1419
|
+
exp.at(-1).slice(expected[ARG_COUNT] ? 2 : 1)
|
1420
|
+
).at(-1),
|
1398
1421
|
copy,
|
1399
1422
|
scope
|
1400
1423
|
)
|
1401
|
-
// console.log(exp.at(-1).slice(1))
|
1402
|
-
// check(exp.at(-1), env, scope)
|
1403
1424
|
// Types.delete(`; ${rootScopeIndex} ${lambdaName}`)
|
1404
1425
|
}
|
1405
1426
|
typeSet(Types, name, env, exp)
|