@@ -293,11 +293,11 @@ export class Resolver extends DiagnosticEmitter {
293
293
// Handle special built-in types
294
294
if (isSimpleType) {
295
295
let text = nameNode.identifier.text;
296
- if (text == CommonNames.native) return this.resolveBuiltinNativeType(node, ctxElement, ctxTypes, reportMode);
297
- if (text == CommonNames.indexof) return this.resolveBuiltinIndexofType(node, ctxElement, ctxTypes, reportMode);
298
- if (text == CommonNames.valueof) return this.resolveBuiltinValueofType(node, ctxElement, ctxTypes, reportMode);
296
+ if (text == CommonNames.native) return this.resolveBuiltinNativeType(node, ctxElement, ctxTypes, reportMode);
297
+ if (text == CommonNames.indexof) return this.resolveBuiltinIndexofType(node, ctxElement, ctxTypes, reportMode);
298
+ if (text == CommonNames.valueof) return this.resolveBuiltinValueofType(node, ctxElement, ctxTypes, reportMode);
299
299
if (text == CommonNames.returnof) return this.resolveBuiltinReturnTypeType(node, ctxElement, ctxTypes, reportMode);
300
- if (text == CommonNames.nonnull) return this.resolveBuiltinNotNullableType(node, ctxElement, ctxTypes, reportMode);
300
+ if (text == CommonNames.nonnull) return this.resolveBuiltinNotNullableType(node, ctxElement, ctxTypes, reportMode);
301
301
}
302
302
303
303
// Resolve normally
@@ -447,17 +447,17 @@ export class Resolver extends DiagnosticEmitter {
447
447
switch (typeArgument.kind) {
448
448
case TypeKind.I8:
449
449
case TypeKind.I16:
450
- case TypeKind.I32: return Type.i32;
450
+ case TypeKind.I32: return Type.i32;
451
451
case TypeKind.ISIZE: if (!this.program.options.isWasm64) return Type.i32;
452
- case TypeKind.I64: return Type.i64;
452
+ case TypeKind.I64: return Type.i64;
453
453
case TypeKind.U8:
454
454
case TypeKind.U16:
455
455
case TypeKind.U32:
456
456
case TypeKind.BOOL: return Type.u32;
457
457
case TypeKind.USIZE: if (!this.program.options.isWasm64) return Type.u32;
458
- case TypeKind.U64: return Type.u64;
459
- case TypeKind.F32: return Type.f32;
460
- case TypeKind.F64: return Type.f64;
458
+ case TypeKind.U64: return Type.u64;
459
+ case TypeKind.F32: return Type.f32;
460
+ case TypeKind.F64: return Type.f64;
461
461
case TypeKind.V128: return Type.v128;
462
462
case TypeKind.VOID: return Type.void;
463
463
default: assert(false);
@@ -491,12 +491,13 @@ export class Resolver extends DiagnosticEmitter {
491
491
}
492
492
var overload = classReference.lookupOverload(OperatorKind.INDEXED_GET);
493
493
if (overload) {
494
+ let parameterTypes = overload.signature.parameterTypes;
494
495
if (overload.is(CommonFlags.STATIC)) {
495
- assert(overload.signature. parameterTypes.length == 2);
496
- return overload.signature. parameterTypes[1];
496
+ assert(parameterTypes.length == 2);
497
+ return parameterTypes[1];
497
498
} else {
498
- assert(overload.signature. parameterTypes.length == 1);
499
- return overload.signature. parameterTypes[0];
499
+ assert(parameterTypes.length == 1);
500
+ return parameterTypes[0];
500
501
}
501
502
}
502
503
if (reportMode == ReportMode.REPORT) {
@@ -631,8 +632,9 @@ export class Resolver extends DiagnosticEmitter {
631
632
/** How to proceed with eventual diagnostics. */
632
633
reportMode: ReportMode = ReportMode.REPORT
633
634
): Type[] | null {
634
- var minParameterCount = 0;
635
- var maxParameterCount = 0;
635
+ var
636
+ minParameterCount = 0,
637
+ maxParameterCount = 0;
636
638
for (let i = 0, k = typeParameters.length; i < k; ++i) {
637
639
if (!typeParameters[i].defaultType) ++minParameterCount;
638
640
++maxParameterCount;
@@ -730,7 +732,9 @@ export class Resolver extends DiagnosticEmitter {
730
732
731
733
// infer types with generic components while updating contextual types
732
734
for (let i = 0; i < numParameters; ++i) {
733
- let argumentExpression = i < numArguments ? argumentNodes[i] : parameterNodes[i].initializer;
735
+ let argumentExpression = i < numArguments
736
+ ? argumentNodes[i]
737
+ : parameterNodes[i].initializer;
734
738
if (!argumentExpression) {
735
739
// optional but not have initializer should be handled in the other place
736
740
if (parameterNodes[i].parameterKind == ParameterKind.OPTIONAL) {
@@ -748,7 +752,15 @@ export class Resolver extends DiagnosticEmitter {
748
752
let typeNode = parameterNodes[i].type;
749
753
if (typeNode.hasGenericComponent(typeParameterNodes)) {
750
754
let type = this.resolveExpression(argumentExpression, ctxFlow, Type.auto, ReportMode.SWALLOW);
751
- if (type) this.propagateInferredGenericTypes(typeNode, type, prototype, contextualTypeArguments, typeParameterNames);
755
+ if (type) {
756
+ this.propagateInferredGenericTypes(
757
+ typeNode,
758
+ type,
759
+ prototype,
760
+ contextualTypeArguments,
761
+ typeParameterNames
762
+ );
763
+ }
752
764
}
753
765
}
754
766
@@ -766,13 +778,19 @@ export class Resolver extends DiagnosticEmitter {
766
778
let defaultType = typeParameterNode.defaultType;
767
779
if (defaultType) {
768
780
// Default parameters are resolved in context of the called function, not the calling function
781
+ let parent = prototype.parent;
769
782
let defaultTypeContextualTypeArguments: Map<string, Type> | null = null;
770
- if (prototype. parent.kind == ElementKind.CLASS) {
771
- defaultTypeContextualTypeArguments = (<Class>prototype. parent).contextualTypeArguments;
772
- } else if (prototype. parent.kind == ElementKind.FUNCTION) {
773
- defaultTypeContextualTypeArguments = (<Function>prototype. parent).contextualTypeArguments;
783
+ if (parent.kind == ElementKind.CLASS) {
784
+ defaultTypeContextualTypeArguments = (<Class>parent).contextualTypeArguments;
785
+ } else if (parent.kind == ElementKind.FUNCTION) {
786
+ defaultTypeContextualTypeArguments = (<Function>parent).contextualTypeArguments;
774
787
}
775
- let resolvedDefaultType = this.resolveType(defaultType, prototype, defaultTypeContextualTypeArguments, reportMode);
788
+ let resolvedDefaultType = this.resolveType(
789
+ defaultType,
790
+ prototype,
791
+ defaultTypeContextualTypeArguments,
792
+ reportMode
793
+ );
776
794
if (!resolvedDefaultType) return null;
777
795
resolvedTypeArguments[i] = resolvedDefaultType;
778
796
continue;
@@ -825,7 +843,13 @@ export class Resolver extends DiagnosticEmitter {
825
843
let typeArguments = classReference.typeArguments;
826
844
if (typeArguments && typeArguments.length == typeArgumentNodes.length) {
827
845
for (let i = 0, k = typeArguments.length; i < k; ++i) {
828
- this.propagateInferredGenericTypes(typeArgumentNodes[i], typeArguments[i], ctxElement, ctxTypes, typeParameterNames);
846
+ this.propagateInferredGenericTypes(
847
+ typeArgumentNodes[i],
848
+ typeArguments[i],
849
+ ctxElement,
850
+ ctxTypes,
851
+ typeParameterNames
852
+ );
829
853
}
830
854
return;
831
855
}
@@ -835,9 +859,10 @@ export class Resolver extends DiagnosticEmitter {
835
859
let name = namedTypeNode.name.identifier.text;
836
860
if (ctxTypes.has(name)) {
837
861
let currentType = assert(ctxTypes.get(name));
838
- if (currentType == Type.auto || (typeParameterNames.has(name) && currentType.isAssignableTo(type))) {
839
- ctxTypes.set(name, type);
840
- }
862
+ if (
863
+ currentType == Type.auto ||
864
+ (typeParameterNames.has(name) && currentType.isAssignableTo(type))
865
+ ) ctxTypes.set(name, type);
841
866
}
842
867
}
843
868
} else if (node.kind == NodeKind.FUNCTIONTYPE) { // foo<T>(bar: (baz: T) => i32))
@@ -847,15 +872,34 @@ export class Resolver extends DiagnosticEmitter {
847
872
if (signatureReference) {
848
873
let parameterTypes = signatureReference.parameterTypes;
849
874
for (let i = 0, k = min(parameterTypes.length, parameterNodes.length) ; i < k; ++i) {
850
- this.propagateInferredGenericTypes(parameterNodes[i].type, parameterTypes[i], ctxElement, ctxTypes, typeParameterNames);
875
+ this.propagateInferredGenericTypes(
876
+ parameterNodes[i].type,
877
+ parameterTypes[i],
878
+ ctxElement,
879
+ ctxTypes,
880
+ typeParameterNames
881
+ );
851
882
}
852
- if (signatureReference.returnType != Type.void) {
853
- this.propagateInferredGenericTypes(functionTypeNode.returnType, signatureReference.returnType, ctxElement, ctxTypes, typeParameterNames);
883
+ let returnType = signatureReference.returnType;
884
+ if (returnType != Type.void) {
885
+ this.propagateInferredGenericTypes(
886
+ functionTypeNode.returnType,
887
+ returnType,
888
+ ctxElement,
889
+ ctxTypes,
890
+ typeParameterNames
891
+ );
854
892
}
855
893
let thisType = signatureReference.thisType;
856
894
let explicitThisType = functionTypeNode.explicitThisType;
857
895
if (thisType && explicitThisType) {
858
- this.propagateInferredGenericTypes(explicitThisType, thisType, ctxElement, ctxTypes, typeParameterNames);
896
+ this.propagateInferredGenericTypes(
897
+ explicitThisType,
898
+ thisType,
899
+ ctxElement,
900
+ ctxTypes,
901
+ typeParameterNames
902
+ );
859
903
}
860
904
return;
861
905
}
@@ -1251,13 +1295,15 @@ export class Resolver extends DiagnosticEmitter {
1251
1295
/** Resolves a lazily compiled global, i.e. a static class field or annotated `@lazy`. */
1252
1296
private ensureResolvedLazyGlobal(global: Global, reportMode: ReportMode = ReportMode.REPORT): bool {
1253
1297
if (global.is(CommonFlags.RESOLVED)) return true;
1254
- var type: Type | null;
1255
1298
var typeNode = global.typeNode;
1256
- if (typeNode) {
1257
- type = this.resolveType(typeNode, global.parent, null, reportMode);
1258
- } else {
1259
- type = this.resolveExpression(assert(global.initializerNode), global.file.startFunction.flow, Type.auto, reportMode);
1260
- }
1299
+ var type = typeNode
1300
+ ? this.resolveType(typeNode, global.parent, null, reportMode)
1301
+ : this.resolveExpression(
1302
+ assert(global.initializerNode),
1303
+ global.file.startFunction.flow,
1304
+ Type.auto,
1305
+ reportMode
1306
+ );
1261
1307
if (!type) return false;
1262
1308
global.setType(type); // also sets resolved
1263
1309
return true;
@@ -2632,7 +2678,7 @@ export class Resolver extends DiagnosticEmitter {
2632
2678
if (
2633
2679
functionType &&
2634
2680
declaration.arrowKind != ArrowKind.NONE &&
2635
- body && body.kind == NodeKind.EXPRESSION &&
2681
+ body && body.kind == NodeKind.EXPRESSION &&
2636
2682
isTypeOmitted(signature.returnType)
2637
2683
) {
2638
2684
// (x) => ret, infer return type accordingt to `ret`
0 commit comments