@magnusopera/fscript 0.78.1 → 0.80.0

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.
@@ -1,9 +1,9 @@
1
1
 
2
2
  import { Span_$reflection, Span, Position } from "./Span.js";
3
- import { iterate as iterate_2, FSharpMap__Add, values, FSharpMap__get_Keys, keys, FSharpMap__TryFind, ofList, toList, FSharpMap__get_Item, FSharpMap__ContainsKey, FSharpMap__get_Count, exists as exists_1, add, fold as fold_1, remove, map as map_1, tryFind, isEmpty, empty } from "../fable_modules/fable-library-js.5.13.0/Map.js";
3
+ import { iterate as iterate_2, FSharpMap__Add, values, forAll, FSharpMap__get_Keys, keys, FSharpMap__TryFind, ofList, toList, FSharpMap__get_Item, FSharpMap__ContainsKey, FSharpMap__get_Count, exists as exists_1, add, fold as fold_1, remove, map as map_1, tryFind, isEmpty, empty } from "../fable_modules/fable-library-js.5.13.0/Map.js";
4
4
  import { disposeSafe, getEnumerator, stringHash, compareArrays, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
5
- import { Types_generalize, Type_$reflection, Types_freshVar, Types_typeToString, Scheme, Type } from "./Types.js";
6
- import { tryFind as tryFind_1, indexed, ofArray, collect, append, iterate, reverse, tryFindIndex, choose, tail as tail_2, cons, head as head_1, isEmpty as isEmpty_1, empty as empty_2, singleton, zip, length, exists, fold, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
5
+ import { Types_generalize, Types_freshNumeric, Type_$reflection, Types_freshVar, Types_typeToString, Scheme, Type } from "./Types.js";
6
+ import { tryFind as tryFind_1, indexed, ofArray, collect, append, reverse, iterate, tryFindIndex, choose, tail as tail_2, cons, head as head_1, isEmpty as isEmpty_1, empty as empty_2, singleton, zip, length, exists, fold, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
7
7
  import { toList as toList_2, ofSeq, contains, add as add_1, empty as empty_1, FSharpSet__Add, FSharpSet__Contains } from "../fable_modules/fable-library-js.5.13.0/Set.js";
8
8
  import { TypeException, TypeError$ } from "./Error.js";
9
9
  import { endsWith, split, join, concat, isNullOrWhiteSpace, printf, toText } from "../fable_modules/fable-library-js.5.13.0/String.js";
@@ -32,30 +32,77 @@ function applyType(s, t) {
32
32
  apply:
33
33
  while (true) {
34
34
  const current = current_mut;
35
+ let matchResult, v;
35
36
  switch (current.tag) {
36
37
  case 15: {
37
- const matchValue = tryFind(current.fields[0], s);
38
+ matchResult = 0;
39
+ v = current.fields[0];
40
+ break;
41
+ }
42
+ case 16: {
43
+ matchResult = 0;
44
+ v = current.fields[0];
45
+ break;
46
+ }
47
+ case 5: {
48
+ matchResult = 1;
49
+ break;
50
+ }
51
+ case 6: {
52
+ matchResult = 2;
53
+ break;
54
+ }
55
+ case 7: {
56
+ matchResult = 3;
57
+ break;
58
+ }
59
+ case 8: {
60
+ matchResult = 4;
61
+ break;
62
+ }
63
+ case 9: {
64
+ matchResult = 5;
65
+ break;
66
+ }
67
+ case 10: {
68
+ matchResult = 6;
69
+ break;
70
+ }
71
+ case 11: {
72
+ matchResult = 7;
73
+ break;
74
+ }
75
+ default:
76
+ matchResult = 8;
77
+ }
78
+ switch (matchResult) {
79
+ case 0: {
80
+ const matchValue = tryFind(v, s);
38
81
  if (matchValue == null) {
39
82
  return current;
40
83
  }
41
- else {
42
- current_mut = matchValue;
84
+ else if (!equals(matchValue, current)) {
85
+ const mapped_1 = matchValue;
86
+ current_mut = mapped_1;
43
87
  continue apply;
44
88
  }
89
+ else {
90
+ return current;
91
+ }
45
92
  }
46
- case 5:
93
+ case 1:
47
94
  return new Type(/* TList */ 5, [apply(current.fields[0])]);
48
- case 6:
95
+ case 2:
49
96
  return new Type(/* TTask */ 6, [apply(current.fields[0])]);
50
- case 7:
97
+ case 3:
51
98
  return new Type(/* TTuple */ 7, [map(apply, current.fields[0])]);
52
- case 8:
99
+ case 4:
53
100
  return new Type(/* TRecord */ 8, [map_1((_arg, t1_2) => apply(t1_2), current.fields[0])]);
54
- case 9:
101
+ case 5:
55
102
  return new Type(/* TMap */ 9, [apply(current.fields[0]), apply(current.fields[1])]);
56
- case 10:
103
+ case 6:
57
104
  return new Type(/* TOption */ 10, [apply(current.fields[0])]);
58
- case 11:
105
+ case 7:
59
106
  return new Type(/* TFun */ 11, [apply(current.fields[0]), apply(current.fields[1])]);
60
107
  default:
61
108
  return current;
@@ -104,7 +151,7 @@ function occurs(v, t) {
104
151
  loop:
105
152
  while (true) {
106
153
  const current = current_mut;
107
- let matchResult, item, keyType, valueType;
154
+ let matchResult, currentVar, item, keyType, valueType;
108
155
  switch (current.tag) {
109
156
  case 7: {
110
157
  matchResult = 2;
@@ -125,6 +172,11 @@ function occurs(v, t) {
125
172
  matchResult = 5;
126
173
  break;
127
174
  }
175
+ case 16: {
176
+ matchResult = 0;
177
+ currentVar = current.fields[0];
178
+ break;
179
+ }
128
180
  case 5: {
129
181
  matchResult = 1;
130
182
  item = current.fields[0];
@@ -152,12 +204,14 @@ function occurs(v, t) {
152
204
  valueType = current.fields[1];
153
205
  break;
154
206
  }
155
- default:
207
+ default: {
156
208
  matchResult = 0;
209
+ currentVar = current.fields[0];
210
+ }
157
211
  }
158
212
  switch (matchResult) {
159
213
  case 0:
160
- return current.fields[0] === v;
214
+ return currentVar === v;
161
215
  case 1: {
162
216
  current_mut = item;
163
217
  continue loop;
@@ -188,13 +242,13 @@ function unify(typeDefs, t1, t2, span) {
188
242
  uni:
189
243
  while (true) {
190
244
  const seen = seen_mut, a = a_mut, b = b_mut;
191
- let arg, arg_1, arg_2, arg_3, arg_4, arg_5;
245
+ let arg, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6;
192
246
  if (FSharpSet__Contains(seen, [a, b]) ? true : FSharpSet__Contains(seen, [b, a])) {
193
247
  return emptySubst;
194
248
  }
195
249
  else {
196
250
  const seen$0027 = FSharpSet__Add(seen, [a, b]);
197
- let matchResult, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xf, yf, kx, ky, vx, vy, x_5, y_5, a1, a2, b1, b2, t, v, name_2, t_1, name_3, t_2;
251
+ let matchResult, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xf, yf, kx, ky, vx, vy, x_5, y_5, a1, a2, b1, b2, t, v, name_2, t_1, name_3, t_2, v_1, w, concrete, v_2, other_4;
198
252
  switch (a.tag) {
199
253
  case 0: {
200
254
  switch (b.tag) {
@@ -214,8 +268,13 @@ function unify(typeDefs, t1, t2, span) {
214
268
  t_2 = a;
215
269
  break;
216
270
  }
271
+ case 16: {
272
+ matchResult = 14;
273
+ other_4 = a;
274
+ break;
275
+ }
217
276
  default:
218
- matchResult = 12;
277
+ matchResult = 15;
219
278
  }
220
279
  break;
221
280
  }
@@ -237,8 +296,14 @@ function unify(typeDefs, t1, t2, span) {
237
296
  t_2 = a;
238
297
  break;
239
298
  }
299
+ case 16: {
300
+ matchResult = 13;
301
+ concrete = a;
302
+ v_2 = b.fields[0];
303
+ break;
304
+ }
240
305
  default:
241
- matchResult = 12;
306
+ matchResult = 15;
242
307
  }
243
308
  break;
244
309
  }
@@ -260,8 +325,14 @@ function unify(typeDefs, t1, t2, span) {
260
325
  t_2 = a;
261
326
  break;
262
327
  }
328
+ case 16: {
329
+ matchResult = 13;
330
+ concrete = a;
331
+ v_2 = b.fields[0];
332
+ break;
333
+ }
263
334
  default:
264
- matchResult = 12;
335
+ matchResult = 15;
265
336
  }
266
337
  break;
267
338
  }
@@ -283,8 +354,13 @@ function unify(typeDefs, t1, t2, span) {
283
354
  t_2 = a;
284
355
  break;
285
356
  }
357
+ case 16: {
358
+ matchResult = 14;
359
+ other_4 = a;
360
+ break;
361
+ }
286
362
  default:
287
- matchResult = 12;
363
+ matchResult = 15;
288
364
  }
289
365
  break;
290
366
  }
@@ -306,8 +382,13 @@ function unify(typeDefs, t1, t2, span) {
306
382
  t_2 = a;
307
383
  break;
308
384
  }
385
+ case 16: {
386
+ matchResult = 14;
387
+ other_4 = a;
388
+ break;
389
+ }
309
390
  default:
310
- matchResult = 12;
391
+ matchResult = 15;
311
392
  }
312
393
  break;
313
394
  }
@@ -329,8 +410,13 @@ function unify(typeDefs, t1, t2, span) {
329
410
  t_2 = a;
330
411
  break;
331
412
  }
413
+ case 16: {
414
+ matchResult = 14;
415
+ other_4 = a;
416
+ break;
417
+ }
332
418
  default:
333
- matchResult = 12;
419
+ matchResult = 15;
334
420
  }
335
421
  break;
336
422
  }
@@ -355,6 +441,12 @@ function unify(typeDefs, t1, t2, span) {
355
441
  v = b.fields[0];
356
442
  break;
357
443
  }
444
+ case 16: {
445
+ matchResult = 10;
446
+ name_2 = a.fields[0];
447
+ t_1 = b;
448
+ break;
449
+ }
358
450
  default: {
359
451
  matchResult = 10;
360
452
  name_2 = a.fields[0];
@@ -383,8 +475,13 @@ function unify(typeDefs, t1, t2, span) {
383
475
  t_2 = a;
384
476
  break;
385
477
  }
478
+ case 16: {
479
+ matchResult = 14;
480
+ other_4 = a;
481
+ break;
482
+ }
386
483
  default:
387
- matchResult = 12;
484
+ matchResult = 15;
388
485
  }
389
486
  break;
390
487
  }
@@ -408,8 +505,13 @@ function unify(typeDefs, t1, t2, span) {
408
505
  t_2 = a;
409
506
  break;
410
507
  }
508
+ case 16: {
509
+ matchResult = 14;
510
+ other_4 = a;
511
+ break;
512
+ }
411
513
  default:
412
- matchResult = 12;
514
+ matchResult = 15;
413
515
  }
414
516
  break;
415
517
  }
@@ -433,8 +535,13 @@ function unify(typeDefs, t1, t2, span) {
433
535
  t_2 = a;
434
536
  break;
435
537
  }
538
+ case 16: {
539
+ matchResult = 14;
540
+ other_4 = a;
541
+ break;
542
+ }
436
543
  default:
437
- matchResult = 12;
544
+ matchResult = 15;
438
545
  }
439
546
  break;
440
547
  }
@@ -458,8 +565,13 @@ function unify(typeDefs, t1, t2, span) {
458
565
  t_2 = a;
459
566
  break;
460
567
  }
568
+ case 16: {
569
+ matchResult = 14;
570
+ other_4 = a;
571
+ break;
572
+ }
461
573
  default:
462
- matchResult = 12;
574
+ matchResult = 15;
463
575
  }
464
576
  break;
465
577
  }
@@ -485,8 +597,13 @@ function unify(typeDefs, t1, t2, span) {
485
597
  t_2 = a;
486
598
  break;
487
599
  }
600
+ case 16: {
601
+ matchResult = 14;
602
+ other_4 = a;
603
+ break;
604
+ }
488
605
  default:
489
- matchResult = 12;
606
+ matchResult = 15;
490
607
  }
491
608
  break;
492
609
  }
@@ -510,8 +627,13 @@ function unify(typeDefs, t1, t2, span) {
510
627
  t_2 = a;
511
628
  break;
512
629
  }
630
+ case 16: {
631
+ matchResult = 14;
632
+ other_4 = a;
633
+ break;
634
+ }
513
635
  default:
514
- matchResult = 12;
636
+ matchResult = 15;
515
637
  }
516
638
  break;
517
639
  }
@@ -537,8 +659,13 @@ function unify(typeDefs, t1, t2, span) {
537
659
  t_2 = a;
538
660
  break;
539
661
  }
662
+ case 16: {
663
+ matchResult = 14;
664
+ other_4 = a;
665
+ break;
666
+ }
540
667
  default:
541
- matchResult = 12;
668
+ matchResult = 15;
542
669
  }
543
670
  break;
544
671
  }
@@ -548,6 +675,45 @@ function unify(typeDefs, t1, t2, span) {
548
675
  v = a.fields[0];
549
676
  break;
550
677
  }
678
+ case 16: {
679
+ switch (b.tag) {
680
+ case 15: {
681
+ matchResult = 9;
682
+ t = a;
683
+ v = b.fields[0];
684
+ break;
685
+ }
686
+ case 12: {
687
+ matchResult = 11;
688
+ name_3 = b.fields[0];
689
+ t_2 = a;
690
+ break;
691
+ }
692
+ case 16: {
693
+ matchResult = 12;
694
+ v_1 = a.fields[0];
695
+ w = b.fields[0];
696
+ break;
697
+ }
698
+ case 1: {
699
+ matchResult = 13;
700
+ concrete = b;
701
+ v_2 = a.fields[0];
702
+ break;
703
+ }
704
+ case 2: {
705
+ matchResult = 13;
706
+ concrete = b;
707
+ v_2 = a.fields[0];
708
+ break;
709
+ }
710
+ default: {
711
+ matchResult = 14;
712
+ other_4 = b;
713
+ }
714
+ }
715
+ break;
716
+ }
551
717
  default:
552
718
  switch (b.tag) {
553
719
  case 15: {
@@ -562,8 +728,13 @@ function unify(typeDefs, t1, t2, span) {
562
728
  t_2 = a;
563
729
  break;
564
730
  }
731
+ case 16: {
732
+ matchResult = 14;
733
+ other_4 = a;
734
+ break;
735
+ }
565
736
  default:
566
- matchResult = 12;
737
+ matchResult = 15;
567
738
  }
568
739
  }
569
740
  switch (matchResult) {
@@ -619,12 +790,17 @@ function unify(typeDefs, t1, t2, span) {
619
790
  if (equals(t, new Type(/* TVar */ 15, [v]))) {
620
791
  return emptySubst;
621
792
  }
793
+ else if (equals(t, new Type(/* TNumeric */ 16, [v]))) {
794
+ return ofList(singleton([v, t]), {
795
+ Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
796
+ });
797
+ }
622
798
  else if (occurs(v, t)) {
623
799
  throw new TypeException(new TypeError$("Occurs check failed", span));
624
800
  }
625
801
  else {
626
802
  return ofList(singleton([v, t]), {
627
- Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
803
+ Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
628
804
  });
629
805
  }
630
806
  case 10: {
@@ -717,15 +893,30 @@ function unify(typeDefs, t1, t2, span) {
717
893
  }
718
894
  }
719
895
  }
896
+ case 12:
897
+ if (v_1 === w) {
898
+ return emptySubst;
899
+ }
900
+ else {
901
+ return ofList(singleton([v_1, new Type(/* TNumeric */ 16, [w])]), {
902
+ Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
903
+ });
904
+ }
905
+ case 13:
906
+ return ofList(singleton([v_2, concrete]), {
907
+ Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
908
+ });
909
+ case 14:
910
+ throw new TypeException(new TypeError$((arg_4 = Types_typeToString(other_4), toText(printf("Expected numeric type, got %s"))(arg_4)), span));
720
911
  default:
721
- throw new TypeException(new TypeError$((arg_4 = Types_typeToString(a), (arg_5 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg_4)(arg_5))), span));
912
+ throw new TypeException(new TypeError$((arg_5 = Types_typeToString(a), (arg_6 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg_5)(arg_6))), span));
722
913
  }
723
914
  }
724
915
  break;
725
916
  }
726
917
  };
727
918
  return uni(empty_1({
728
- Compare: (x_7, y_7) => (compareArrays(x_7, y_7) | 0),
919
+ Compare: (x_10, y_10) => (compareArrays(x_10, y_10) | 0),
729
920
  }), t1, t2);
730
921
  }
731
922
 
@@ -737,6 +928,28 @@ function instantiate(_arg) {
737
928
  switch (t_1.tag) {
738
929
  case 15:
739
930
  return defaultArg(tryFind(t_1.fields[0], freshMap), t_1);
931
+ case 16: {
932
+ const matchValue = tryFind(t_1.fields[0], freshMap);
933
+ let matchResult, fresh;
934
+ if (matchValue != null) {
935
+ if (matchValue.tag === 15) {
936
+ matchResult = 0;
937
+ fresh = matchValue.fields[0];
938
+ }
939
+ else {
940
+ matchResult = 1;
941
+ }
942
+ }
943
+ else {
944
+ matchResult = 1;
945
+ }
946
+ switch (matchResult) {
947
+ case 0:
948
+ return new Type(/* TNumeric */ 16, [fresh]);
949
+ default:
950
+ return t_1;
951
+ }
952
+ }
740
953
  case 5:
741
954
  return new Type(/* TList */ 5, [subst(t_1.fields[0])]);
742
955
  case 6:
@@ -936,6 +1149,8 @@ function builtinType(name) {
936
1149
  return Type.TInt;
937
1150
  case "float":
938
1151
  return Type.TFloat;
1152
+ case "numeric":
1153
+ return Types_freshNumeric();
939
1154
  case "bool":
940
1155
  return Type.TBool;
941
1156
  case "string":
@@ -1068,11 +1283,15 @@ function annotationTypeFromRef(typeDefs, span, tref) {
1068
1283
  default:
1069
1284
  throw new TypeException(new TypeError$(concat("Unknown type suffix \'", tref.fields[1], "\'"), span));
1070
1285
  }
1071
- case 4:
1286
+ case 4: {
1287
+ const key = annotationTypeFromRef(typeDefs, span, tref.fields[0]);
1288
+ return new Type(/* TMap */ 9, [(key.tag === 16) ? Type.TInt : key, annotationTypeFromRef(typeDefs, span, tref.fields[1])]);
1289
+ }
1290
+ case 5:
1072
1291
  return resolveNamedRecordByShape(typeDefs, ofList(map((tupledArg) => [tupledArg[0], annotationTypeFromRef(typeDefs, span, tupledArg[1])], tref.fields[0]), {
1073
1292
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
1074
1293
  }), span);
1075
- case 5:
1294
+ case 6:
1076
1295
  return new Type(/* TRecord */ 8, [ofList(map((tupledArg_1) => [tupledArg_1[0], annotationTypeFromRef(typeDefs, span, tupledArg_1[1])], tref.fields[0]), {
1077
1296
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
1078
1297
  })]);
@@ -1084,6 +1303,8 @@ function annotationTypeFromRef(typeDefs, span, tref) {
1084
1303
  return Type.TInt;
1085
1304
  case "float":
1086
1305
  return Type.TFloat;
1306
+ case "numeric":
1307
+ return Types_freshNumeric();
1087
1308
  case "bool":
1088
1309
  return Type.TBool;
1089
1310
  case "string":
@@ -1131,11 +1352,15 @@ function typeFromRef(decls, stack, tref) {
1131
1352
  throw new TypeException(new TypeError$(concat("Unknown type suffix \'", suffix, "\'"), unknownSpan));
1132
1353
  }
1133
1354
  }
1134
- case 4:
1355
+ case 4: {
1356
+ const key = typeFromRef(decls, stack, tref.fields[0]);
1357
+ return new Type(/* TMap */ 9, [(key.tag === 16) ? Type.TInt : key, typeFromRef(decls, stack, tref.fields[1])]);
1358
+ }
1359
+ case 5:
1135
1360
  return new Type(/* TRecord */ 8, [ofList(map((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, stack, tupledArg_1[1])], tref.fields[0]), {
1136
1361
  Compare: (x_1, y_2) => (comparePrimitives(x_1, y_2) | 0),
1137
1362
  })]);
1138
- case 5:
1363
+ case 6:
1139
1364
  return new Type(/* TRecord */ 8, [ofList(map((tupledArg_2) => [tupledArg_2[0], typeFromRef(decls, stack, tupledArg_2[1])], tref.fields[0]), {
1140
1365
  Compare: (x_2, y_3) => (comparePrimitives(x_2, y_3) | 0),
1141
1366
  })]);
@@ -1181,6 +1406,137 @@ function typeFromRef(decls, stack, tref) {
1181
1406
  }
1182
1407
  }
1183
1408
 
1409
+ function ensureSupportedMapKeyType(typeDefs, span, t) {
1410
+ switch (t.tag) {
1411
+ case 4:
1412
+ case 1:
1413
+ case 3:
1414
+ case 15:
1415
+ case 16: {
1416
+ break;
1417
+ }
1418
+ case 12: {
1419
+ const matchValue = FSharpMap__TryFind(typeDefs, t.fields[0]);
1420
+ let matchResult, cases_1;
1421
+ if (matchValue != null) {
1422
+ if (matchValue.tag === 13) {
1423
+ if (forAll((_arg, payload) => (payload == null), matchValue.fields[1])) {
1424
+ matchResult = 0;
1425
+ cases_1 = matchValue.fields[1];
1426
+ }
1427
+ else {
1428
+ matchResult = 1;
1429
+ }
1430
+ }
1431
+ else {
1432
+ matchResult = 1;
1433
+ }
1434
+ }
1435
+ else {
1436
+ matchResult = 1;
1437
+ }
1438
+ switch (matchResult) {
1439
+ case 0: {
1440
+ break;
1441
+ }
1442
+ case 1: {
1443
+ throw new TypeException(new TypeError$(concat("Map key type must be string, int, bool, or a payload-free union, got ", Types_typeToString(t)), span));
1444
+ break;
1445
+ }
1446
+ }
1447
+ break;
1448
+ }
1449
+ default:
1450
+ throw new TypeException(new TypeError$(concat("Map key type must be string, int, bool, or a payload-free union, got ", Types_typeToString(t)), span));
1451
+ }
1452
+ }
1453
+
1454
+ function constrainMapKeyTypes(typeDefs, span, t) {
1455
+ let subst = emptySubst;
1456
+ const loop = (current_mut) => {
1457
+ loop:
1458
+ while (true) {
1459
+ const current = current_mut;
1460
+ const matchValue = applyType(subst, current);
1461
+ let matchResult, inner;
1462
+ switch (matchValue.tag) {
1463
+ case 9: {
1464
+ matchResult = 0;
1465
+ break;
1466
+ }
1467
+ case 5: {
1468
+ matchResult = 1;
1469
+ inner = matchValue.fields[0];
1470
+ break;
1471
+ }
1472
+ case 6: {
1473
+ matchResult = 1;
1474
+ inner = matchValue.fields[0];
1475
+ break;
1476
+ }
1477
+ case 10: {
1478
+ matchResult = 1;
1479
+ inner = matchValue.fields[0];
1480
+ break;
1481
+ }
1482
+ case 7: {
1483
+ matchResult = 2;
1484
+ break;
1485
+ }
1486
+ case 8: {
1487
+ matchResult = 3;
1488
+ break;
1489
+ }
1490
+ case 11: {
1491
+ matchResult = 4;
1492
+ break;
1493
+ }
1494
+ default:
1495
+ matchResult = 5;
1496
+ }
1497
+ switch (matchResult) {
1498
+ case 0: {
1499
+ const keyType = matchValue.fields[0];
1500
+ if (keyType.tag === 16) {
1501
+ subst = compose(unify(typeDefs, keyType, Type.TInt, span), subst);
1502
+ }
1503
+ else {
1504
+ ensureSupportedMapKeyType(typeDefs, span, keyType);
1505
+ }
1506
+ current_mut = matchValue.fields[1];
1507
+ continue loop;
1508
+ break;
1509
+ }
1510
+ case 1: {
1511
+ current_mut = inner;
1512
+ continue loop;
1513
+ break;
1514
+ }
1515
+ case 2: {
1516
+ iterate(loop, matchValue.fields[0]);
1517
+ break;
1518
+ }
1519
+ case 3: {
1520
+ iterate_1(loop, values(matchValue.fields[0]));
1521
+ break;
1522
+ }
1523
+ case 4: {
1524
+ loop(matchValue.fields[0]);
1525
+ current_mut = matchValue.fields[1];
1526
+ continue loop;
1527
+ break;
1528
+ }
1529
+ case 5: {
1530
+ break;
1531
+ }
1532
+ }
1533
+ break;
1534
+ }
1535
+ };
1536
+ loop(t);
1537
+ return subst;
1538
+ }
1539
+
1184
1540
  function inferPattern(telemetry, typeDefs, constructors, pat) {
1185
1541
  let table_5;
1186
1542
  switch (pat.tag) {
@@ -1240,15 +1596,8 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1240
1596
  const tailPattern = pat.fields[1];
1241
1597
  const span_1 = pat.fields[2];
1242
1598
  const startIndex_1 = currentTelemetryCaptureCount(telemetry) | 0;
1243
- const ensureSupportedMapKeyType = (t_1) => {
1244
- switch (t_1.tag) {
1245
- case 4:
1246
- case 15: {
1247
- break;
1248
- }
1249
- default:
1250
- throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(t_1)), span_1));
1251
- }
1599
+ const ensureSupportedMapKeyType_1 = (t_1) => {
1600
+ ensureSupportedMapKeyType(typeDefs, span_1, t_1);
1252
1601
  };
1253
1602
  const mapKeyType = Types_freshVar();
1254
1603
  const valueType = Types_freshVar();
@@ -1264,7 +1613,7 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1264
1613
  const patternInput_7 = inferPattern(telemetry, typeDefs, constructors, forLoopVar[1]);
1265
1614
  const sKey = unify(typeDefs, applyType(sAcc, patternInput_6[1]), applyType(sAcc, mapKeyType), span_1);
1266
1615
  sAcc = compose(sKey, sAcc);
1267
- ensureSupportedMapKeyType(applyType(sAcc, mapKeyType));
1616
+ ensureSupportedMapKeyType_1(applyType(sAcc, mapKeyType));
1268
1617
  const sValue = unify(typeDefs, applyType(sAcc, patternInput_7[1]), applyType(sAcc, valueType), span_1);
1269
1618
  sAcc = compose(sValue, sAcc);
1270
1619
  const mergedClauseEnv = map_1((_arg_1, t_2) => applyType(sAcc, t_2), fold_1((acc_3, k_3, v_3) => add(k_3, v_3, acc_3), patternInput_7[0], patternInput_6[0]));
@@ -1283,7 +1632,7 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1283
1632
  sAcc = compose(sTail, sAcc);
1284
1633
  envAcc_2 = ((table_5 = map_1((_arg_2, t_3) => applyType(sAcc, t_3), patternInput_8[0]), fold_1((acc_5, k_5, v_5) => add(k_5, v_5, acc_5), envAcc_2, table_5)));
1285
1634
  }
1286
- ensureSupportedMapKeyType(applyType(sAcc, mapKeyType));
1635
+ ensureSupportedMapKeyType_1(applyType(sAcc, mapKeyType));
1287
1636
  applySubstToCapturedLocals(telemetry, startIndex_1, sAcc);
1288
1637
  return [map_1((_arg_3, t_4) => applyType(sAcc, t_4), envAcc_2), new Type(/* TMap */ 9, [applyType(sAcc, mapKeyType), applyType(sAcc, valueType)])];
1289
1638
  }
@@ -1346,19 +1695,21 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1346
1695
  }
1347
1696
  }
1348
1697
 
1349
- function numericResult(t, span) {
1698
+ function constrainNumeric(typeDefs, t, span) {
1350
1699
  switch (t.tag) {
1351
1700
  case 1:
1352
1701
  case 2:
1353
- return t;
1354
- case 15:
1355
- return Type.TInt;
1356
- default:
1357
- throw new TypeException(new TypeError$("Expected numeric type", span));
1702
+ case 16:
1703
+ return [emptySubst, t];
1704
+ default: {
1705
+ const numeric = Types_freshNumeric();
1706
+ const subst = unify(typeDefs, t, numeric, span);
1707
+ return [subst, applyType(subst, numeric)];
1708
+ }
1358
1709
  }
1359
1710
  }
1360
1711
 
1361
- function validateMapKeyTypes(span, t) {
1712
+ function validateMapKeyTypes(typeDefs, span, t) {
1362
1713
  const loop = (t_1_mut) => {
1363
1714
  loop:
1364
1715
  while (true) {
@@ -1368,14 +1719,7 @@ function validateMapKeyTypes(span, t) {
1368
1719
  const keyType = t_1.fields[0];
1369
1720
  loop(keyType);
1370
1721
  loop(t_1.fields[1]);
1371
- switch (keyType.tag) {
1372
- case 4:
1373
- case 15: {
1374
- break;
1375
- }
1376
- default:
1377
- throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(keyType)), span));
1378
- }
1722
+ ensureSupportedMapKeyType(typeDefs, span, keyType);
1379
1723
  break;
1380
1724
  }
1381
1725
  case 5: {
@@ -1417,6 +1761,15 @@ function validateMapKeyTypes(span, t) {
1417
1761
  }
1418
1762
 
1419
1763
  function inferExpr(telemetry, typeDefs, constructors, env, expr) {
1764
+ const patternInput = inferExprRaw(telemetry, typeDefs, constructors, env, expr);
1765
+ const subst = patternInput[0];
1766
+ const inferred = patternInput[1];
1767
+ const combined = compose(constrainMapKeyTypes(typeDefs, Ast_spanOfExpr(expr), applyType(subst, inferred)), subst);
1768
+ const resolved = applyType(combined, inferred);
1769
+ return [combined, resolved, asTyped(expr, resolved)];
1770
+ }
1771
+
1772
+ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
1420
1773
  let expectedReturn, expectedReturn_1;
1421
1774
  switch (expr.tag) {
1422
1775
  case 1: {
@@ -1490,12 +1843,15 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
1490
1843
  return [s1_1, tFun, asTyped(expr, tFun)];
1491
1844
  }
1492
1845
  case 5: {
1846
+ const span_4 = expr.fields[2];
1493
1847
  const patternInput_3 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
1494
1848
  const s1_2 = patternInput_3[0];
1495
1849
  const patternInput_4 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_2, env), expr.fields[1]);
1850
+ const t2 = patternInput_4[1];
1496
1851
  const s2 = patternInput_4[0];
1497
1852
  const tv_1 = Types_freshVar();
1498
- const s_1 = compose(unify(typeDefs, applyType(s2, patternInput_3[1]), new Type(/* TFun */ 11, [patternInput_4[1], tv_1]), expr.fields[2]), compose(s2, s1_2));
1853
+ const combined = compose(unify(typeDefs, applyType(s2, patternInput_3[1]), new Type(/* TFun */ 11, [t2, tv_1]), span_4), compose(s2, s1_2));
1854
+ const s_1 = compose(constrainMapKeyTypes(typeDefs, span_4, applyType(combined, new Type(/* TFun */ 11, [t2, tv_1]))), combined);
1499
1855
  const tRes = applyType(s_1, tv_1);
1500
1856
  return [s_1, tRes, asTyped(expr, tRes)];
1501
1857
  }
@@ -1859,15 +2215,8 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
1859
2215
  return [sAcc_5, tRes_8, asTyped(expr, tRes_8)];
1860
2216
  }
1861
2217
  case 18: {
1862
- const ensureSupportedMapKeyType = (t_3) => {
1863
- switch (t_3.tag) {
1864
- case 4:
1865
- case 15: {
1866
- break;
1867
- }
1868
- default:
1869
- throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(t_3)), expr.fields[1]));
1870
- }
2218
+ const ensureSupportedMapKeyType_1 = (t_3) => {
2219
+ ensureSupportedMapKeyType(typeDefs, expr.fields[1], t_3);
1871
2220
  };
1872
2221
  const keyType = Types_freshVar();
1873
2222
  const valueType = Types_freshVar();
@@ -1890,7 +2239,7 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
1890
2239
  const patternInput_30 = inferExpr(telemetry, typeDefs, constructors, applyEnv(sAcc_6, env), keyExpr);
1891
2240
  const sKey = patternInput_30[0];
1892
2241
  const sAfterKey = compose(unify(typeDefs, applyType(sKey, patternInput_30[1]), applyType(sKey, applyType(sAcc_6, keyType)), Ast_spanOfExpr(keyExpr)), compose(sKey, sAcc_6));
1893
- ensureSupportedMapKeyType(applyType(sAfterKey, keyType));
2242
+ ensureSupportedMapKeyType_1(applyType(sAfterKey, keyType));
1894
2243
  const patternInput_31 = inferExpr(telemetry, typeDefs, constructors, applyEnv(sAfterKey, env), valueExpr_3);
1895
2244
  const sValue_3 = patternInput_31[0];
1896
2245
  const sValueType = unify(typeDefs, applyType(sValue_3, applyType(sAfterKey, valueType)), patternInput_31[1], Ast_spanOfExpr(valueExpr_3));
@@ -1901,7 +2250,7 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
1901
2250
  finally {
1902
2251
  disposeSafe(enumerator_8);
1903
2252
  }
1904
- ensureSupportedMapKeyType(applyType(sAcc_6, keyType));
2253
+ ensureSupportedMapKeyType_1(applyType(sAcc_6, keyType));
1905
2254
  const tRes_9 = new Type(/* TMap */ 9, [applyType(sAcc_6, keyType), applyType(sAcc_6, valueType)]);
1906
2255
  return [sAcc_6, tRes_9, asTyped(expr, tRes_9)];
1907
2256
  }
@@ -2150,7 +2499,9 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
2150
2499
  matchResult_6 = 2;
2151
2500
  break;
2152
2501
  }
2153
- case 4: {
2502
+ case 4:
2503
+ case 3:
2504
+ case 12: {
2154
2505
  matchResult_6 = 3;
2155
2506
  break;
2156
2507
  }
@@ -2174,15 +2525,7 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
2174
2525
  }
2175
2526
  case 1: {
2176
2527
  const s_13 = compose(unify(typeDefs, keyType_1, mapKeyType, span_19), compose(s2_10, s1_19));
2177
- const matchValue_19 = applyType(s_13, mapKeyType);
2178
- switch (matchValue_19.tag) {
2179
- case 4:
2180
- case 15: {
2181
- break;
2182
- }
2183
- default:
2184
- throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(matchValue_19)), span_19));
2185
- }
2528
+ ensureSupportedMapKeyType(typeDefs, span_19, applyType(s_13, mapKeyType));
2186
2529
  const tRes_13 = new Type(/* TOption */ 10, [applyType(s_13, valueType_1)]);
2187
2530
  return [s_13, tRes_13, asTyped(expr, tRes_13)];
2188
2531
  }
@@ -2194,12 +2537,13 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
2194
2537
  }
2195
2538
  case 3: {
2196
2539
  const valueType_2 = Types_freshVar();
2197
- const s_15 = compose(unify(typeDefs, targetType, new Type(/* TMap */ 9, [Type.TString, valueType_2]), span_19), compose(s2_10, s1_19));
2540
+ ensureSupportedMapKeyType(typeDefs, span_19, keyType_1);
2541
+ const s_15 = compose(unify(typeDefs, targetType, new Type(/* TMap */ 9, [keyType_1, valueType_2]), span_19), compose(s2_10, s1_19));
2198
2542
  const tRes_15 = new Type(/* TOption */ 10, [applyType(s_15, valueType_2)]);
2199
2543
  return [s_15, tRes_15, asTyped(expr, tRes_15)];
2200
2544
  }
2201
2545
  case 4:
2202
- throw new TypeException(new TypeError$("Ambiguous index access: use a list with int index or a map with string key", span_19));
2546
+ throw new TypeException(new TypeError$("Ambiguous index access: annotate the list or map target", span_19));
2203
2547
  default:
2204
2548
  throw new TypeException(new TypeError$(concat("Index access requires a ", (keyType_1.tag === 1) ? "list" : ((keyType_1.tag === 4) ? "map" : "list or map"), " target with a compatible index type"), span_19));
2205
2549
  }
@@ -2212,11 +2556,13 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
2212
2556
  switch (op) {
2213
2557
  case "|>": {
2214
2558
  const patternInput_43 = inferExpr(telemetry, typeDefs, constructors, env, a);
2559
+ const tLeft = patternInput_43[1];
2215
2560
  const s1_20 = patternInput_43[0];
2216
2561
  const patternInput_44 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_20, env), b);
2217
2562
  const s2_11 = patternInput_44[0];
2218
2563
  const tv_7 = Types_freshVar();
2219
- const s_16 = compose(unify(typeDefs, applyType(s2_11, patternInput_44[1]), new Type(/* TFun */ 11, [applyType(s2_11, patternInput_43[1]), tv_7]), span_20), compose(s2_11, s1_20));
2564
+ const combined_1 = compose(unify(typeDefs, applyType(s2_11, patternInput_44[1]), new Type(/* TFun */ 11, [applyType(s2_11, tLeft), tv_7]), span_20), compose(s2_11, s1_20));
2565
+ const s_16 = compose(constrainMapKeyTypes(typeDefs, span_20, applyType(combined_1, new Type(/* TFun */ 11, [tLeft, tv_7]))), combined_1);
2220
2566
  const tRes_16 = applyType(s_16, tv_7);
2221
2567
  return [s_16, tRes_16, asTyped(expr, tRes_16)];
2222
2568
  }
@@ -2248,70 +2594,72 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
2248
2594
  const t2_3 = patternInput_50[1];
2249
2595
  const s2_14 = patternInput_50[0];
2250
2596
  const s3_11 = unify(typeDefs, applyType(s2_14, patternInput_49[1]), t2_3, span_20);
2251
- const t_9 = applyType(s3_11, t2_3);
2252
- let resultType;
2597
+ const t_8 = applyType(s3_11, t2_3);
2598
+ let patternInput_52;
2253
2599
  switch (op) {
2254
2600
  case "+":
2255
2601
  case "-":
2256
2602
  case "*":
2257
- case "/":
2603
+ case "/": {
2604
+ patternInput_52 = constrainNumeric(typeDefs, t_8, span_20);
2605
+ break;
2606
+ }
2258
2607
  case "%": {
2259
- resultType = numericResult(t_9, span_20);
2608
+ patternInput_52 = [unify(typeDefs, t_8, Type.TInt, span_20), Type.TInt];
2260
2609
  break;
2261
2610
  }
2262
2611
  case "=": {
2263
- resultType = Type.TBool;
2612
+ patternInput_52 = [emptySubst, Type.TBool];
2264
2613
  break;
2265
2614
  }
2266
2615
  case "<":
2267
2616
  case ">":
2268
2617
  case "<=":
2269
2618
  case ">=": {
2270
- numericResult(t_9, span_20);
2271
- resultType = Type.TBool;
2619
+ patternInput_52 = [constrainNumeric(typeDefs, t_8, span_20)[0], Type.TBool];
2272
2620
  break;
2273
2621
  }
2274
2622
  case "&&":
2275
2623
  case "||": {
2276
- unify(typeDefs, t_9, Type.TBool, span_20);
2277
- resultType = Type.TBool;
2624
+ patternInput_52 = [unify(typeDefs, t_8, Type.TBool, span_20), Type.TBool];
2278
2625
  break;
2279
2626
  }
2280
2627
  default:
2281
2628
  throw new TypeException(new TypeError$(toText(printf("Unknown operator %s"))(op), span_20));
2282
2629
  }
2283
- return [compose(s3_11, compose(s2_14, s1_23)), resultType, asTyped(expr, resultType)];
2630
+ const resultType = patternInput_52[1];
2631
+ return [compose(patternInput_52[0], compose(s3_11, compose(s2_14, s1_23))), resultType, asTyped(expr, resultType)];
2284
2632
  }
2285
2633
  }
2286
2634
  }
2287
2635
  case 26: {
2288
- const patternInput_51 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2289
- const t1_11 = patternInput_51[1];
2290
- return [patternInput_51[0], new Type(/* TOption */ 10, [t1_11]), asTyped(expr, new Type(/* TOption */ 10, [t1_11]))];
2636
+ const patternInput_53 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2637
+ const t1_11 = patternInput_53[1];
2638
+ return [patternInput_53[0], new Type(/* TOption */ 10, [t1_11]), asTyped(expr, new Type(/* TOption */ 10, [t1_11]))];
2291
2639
  }
2292
2640
  case 27: {
2293
2641
  const tv_9 = Types_freshVar();
2294
2642
  return [emptySubst, new Type(/* TOption */ 10, [tv_9]), asTyped(expr, new Type(/* TOption */ 10, [tv_9]))];
2295
2643
  }
2296
2644
  case 23: {
2297
- const patternInput_52 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2298
- const t1_12 = patternInput_52[1];
2299
- const s1_25 = patternInput_52[0];
2300
- const patternInput_53 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_25, env), expr.fields[1]);
2301
- const s2_15 = patternInput_53[0];
2302
- const s_20 = compose(unify(typeDefs, applyType(s2_15, patternInput_53[1]), new Type(/* TList */ 5, [t1_12]), expr.fields[2]), compose(s2_15, s1_25));
2645
+ const patternInput_54 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2646
+ const t1_12 = patternInput_54[1];
2647
+ const s1_25 = patternInput_54[0];
2648
+ const patternInput_55 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_25, env), expr.fields[1]);
2649
+ const s2_15 = patternInput_55[0];
2650
+ const s_20 = compose(unify(typeDefs, applyType(s2_15, patternInput_55[1]), new Type(/* TList */ 5, [t1_12]), expr.fields[2]), compose(s2_15, s1_25));
2303
2651
  const tRes_19 = applyType(s_20, new Type(/* TList */ 5, [t1_12]));
2304
2652
  return [s_20, tRes_19, asTyped(expr, tRes_19)];
2305
2653
  }
2306
2654
  case 24: {
2307
2655
  const span_22 = expr.fields[2];
2308
- const patternInput_54 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2309
- const s1_26 = patternInput_54[0];
2310
- const patternInput_55 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_26, env), expr.fields[1]);
2311
- const s2_16 = patternInput_55[0];
2656
+ const patternInput_56 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2657
+ const s1_26 = patternInput_56[0];
2658
+ const patternInput_57 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_26, env), expr.fields[1]);
2659
+ const s2_16 = patternInput_57[0];
2312
2660
  const tv_10 = Types_freshVar();
2313
- const s3_13 = unify(typeDefs, applyType(s2_16, patternInput_54[1]), new Type(/* TList */ 5, [tv_10]), span_22);
2314
- const s_21 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16, patternInput_55[1])), new Type(/* TList */ 5, [applyType(s3_13, tv_10)]), span_22), compose(s3_13, compose(s2_16, s1_26)));
2661
+ const s3_13 = unify(typeDefs, applyType(s2_16, patternInput_56[1]), new Type(/* TList */ 5, [tv_10]), span_22);
2662
+ const s_21 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16, patternInput_57[1])), new Type(/* TList */ 5, [applyType(s3_13, tv_10)]), span_22), compose(s3_13, compose(s2_16, s1_26)));
2315
2663
  const tRes_20 = new Type(/* TList */ 5, [applyType(s_21, tv_10)]);
2316
2664
  return [s_21, tRes_20, asTyped(expr, tRes_20)];
2317
2665
  }
@@ -2476,7 +2824,7 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2476
2824
  applySubstToCapturedLocals(telemetry, startIndex, s);
2477
2825
  const env$0027 = applyEnv(s, env);
2478
2826
  const inferred = applyType(s, t1);
2479
- validateMapKeyTypes(span_1, inferred);
2827
+ validateMapKeyTypes(typeDefs, span_1, inferred);
2480
2828
  const scheme_1 = Types_generalize(env$0027, inferred);
2481
2829
  env = add(name_2, scheme_1, env$0027);
2482
2830
  void (typed.push(new TypedStmt(/* TSLet */ 1, [name_2, exprVal, inferred, true, isExported, span_1])));
@@ -2489,7 +2837,7 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2489
2837
  applySubstToCapturedLocals(telemetry, startIndex, s_1);
2490
2838
  const env$0027_1 = applyEnv(s_1, env);
2491
2839
  const inferred_1 = applyType(s_1, t1_1);
2492
- validateMapKeyTypes(span_1, inferred_1);
2840
+ validateMapKeyTypes(typeDefs, span_1, inferred_1);
2493
2841
  const scheme_2 = Types_generalize(env$0027_1, inferred_1);
2494
2842
  env = add(name_2, scheme_2, env$0027_1);
2495
2843
  void (typed.push(new TypedStmt(/* TSLet */ 1, [name_2, exprVal, inferred_1, false, isExported, span_1])));
@@ -2516,7 +2864,7 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2516
2864
  const envBase = applyEnv(s_2, env);
2517
2865
  const typedBindings = map_1((_arg_1, ty) => applyType(s_2, ty), patternInput_3[0]);
2518
2866
  iterate_2((_arg_2, ty_1) => {
2519
- validateMapKeyTypes(span_2, ty_1);
2867
+ validateMapKeyTypes(typeDefs, span_2, ty_1);
2520
2868
  }, typedBindings);
2521
2869
  env = fold_1((state_1, name_3, bindingType) => add(name_3, Types_generalize(envBase, bindingType), state_1), envBase, typedBindings);
2522
2870
  void (typed.push(new TypedStmt(/* TSLetPattern */ 2, [pattern, expr_1, typedBindings, stmt.fields[2], span_2])));
@@ -2581,7 +2929,7 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2581
2929
  const schemes = map((tupledArg_8) => {
2582
2930
  const name_9 = tupledArg_8[0];
2583
2931
  const inferred_2 = applyType(sRec, FSharpMap__get_Item(freshByName, name_9));
2584
- validateMapKeyTypes(span_3, inferred_2);
2932
+ validateMapKeyTypes(typeDefs, span_3, inferred_2);
2585
2933
  return [name_9, Types_generalize(envGeneralize, inferred_2)];
2586
2934
  }, foldedBindings);
2587
2935
  const typedBindings_1 = map((tupledArg_9) => {
@@ -2607,7 +2955,7 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2607
2955
  const s1_4 = patternInput_5[0];
2608
2956
  const s_3 = compose((forLoopVar[0] < (length(program) - 1)) ? unify(typeDefs, applyType(s1_4, t1_3), Type.TUnit, Ast_spanOfExpr(expr_2)) : emptySubst, s1_4);
2609
2957
  applySubstToCapturedLocals(telemetry, startIndex_3, s_3);
2610
- validateMapKeyTypes(Ast_spanOfExpr(expr_2), applyType(s_3, t1_3));
2958
+ validateMapKeyTypes(typeDefs, Ast_spanOfExpr(expr_2), applyType(s_3, t1_3));
2611
2959
  env = applyEnv(s_3, env);
2612
2960
  void (typed.push(new TypedStmt(/* TSExpr */ 4, [patternInput_5[2]])));
2613
2961
  break;