Skip to content
19 changes: 16 additions & 3 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5543,8 +5543,11 @@ export class Compiler extends DiagnosticEmitter {
}
return this.module.unreachable();
}
assert(indexedSet.signature.parameterTypes.length == 2); // parser must guarantee this
targetType = indexedSet.signature.parameterTypes[1]; // 2nd parameter is the element
let parameterTypes = indexedSet.signature.parameterTypes;

assert(parameterTypes.length == 2); // parser must guarantee this
targetType = parameterTypes[1]; // 2nd parameter is the element

if (indexedSet.hasDecorator(DecoratorFlags.UNSAFE)) this.checkUnsafe(expression);
if (!isUnchecked && this.options.pedantic) {
this.pedantic(
Expand Down Expand Up @@ -5735,7 +5738,17 @@ export class Compiler extends DiagnosticEmitter {
thisType,
Constraints.CONV_IMPLICIT | Constraints.IS_THIS
);
let elementExpr = this.compileExpression(assert(indexExpression), Type.i32, Constraints.CONV_IMPLICIT);
let setterIndexType = setterInstance.signature.parameterTypes[0];
let getterIndexType = getterInstance.signature.parameterTypes[0];
if (!setterIndexType.equals(getterIndexType)) {
this.error(
DiagnosticCode.Index_signature_type_should_be_the_same_for_element_accessors_in_type_0,
valueExpression.range, classInstance.internalName
);
this.currentType = tee ? getterInstance.signature.returnType : Type.void;
return module.unreachable();
}
let elementExpr = this.compileExpression(assert(indexExpression), setterIndexType, Constraints.CONV_IMPLICIT);
let elementType = this.currentType;
if (tee) {
let tempTarget = flow.getTempLocal(thisType);
Expand Down
1 change: 1 addition & 0 deletions src/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"Start function name '{0}' is invalid or conflicts with another export.": 110,
"Element '{0}' not found.": 111,
"Exchange of '{0}' values is not supported by all embeddings": 112,
"Index signature type should be the same for element accessors in type '{0}'.": 113,

"Conversion from type '{0}' to '{1}' requires an explicit cast.": 200,
"Conversion from type '{0}' to '{1}' will require an explicit cast when switching between 32/64-bit.": 201,
Expand Down
Loading