Use the element type annotated on the setter when doing indexed sets

This commit is contained in:
dcodeIO 2018-04-23 16:17:33 +02:00
parent 78a3dcfaf0
commit 88b00c1689
7 changed files with 1499 additions and 2258 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,11 @@
"private": true,
"scripts": {
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -a build/optimized.asm.js -O3 --validate --noDebug --noAssert",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --validate --noDebug --noAssert",
"asbuild:asmjs": "asc assembly/index.ts -a build/index.asm.js -O3 --validate --noDebug --noAssert",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized && npm run asbuild:asmjs",
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
"build": "npm run asbuild && npm run tsbuild",
"server": "http-server . -o -c-1",
"test": "node tests"
},

View File

@ -4,7 +4,7 @@ const fs = require("fs");
const nbodyWASM = require("../index.js");
// Load ASMJS version
src = fs.readFileSync(__dirname + "/../build/optimized.asm.js", "utf8");
src = fs.readFileSync(__dirname + "/../build/index.asm.js", "utf8");
if (src.indexOf("var Math_sqrt =") < 0) { // currently missing in asm.js output
let p = src.indexOf(" var abort = env.abort;");
src = src.substring(0, p) + " var Math_sqrt = global.Math.sqrt;\n " + src.substring(p);

View File

@ -4281,15 +4281,24 @@ export class Compiler extends DiagnosticEmitter {
}
case ElementKind.CLASS: {
if (program.resolvedElementExpression) { // indexed access
let indexedGet = (<Class>target).lookupOverload(OperatorKind.INDEXED_GET);
if (!indexedGet) {
this.error(
DiagnosticCode.Index_signature_is_missing_in_type_0,
expression.range, (<Class>target).internalName
);
let indexedSet = (<Class>target).lookupOverload(OperatorKind.INDEXED_SET);
if (!indexedSet) {
let indexedGet = (<Class>target).lookupOverload(OperatorKind.INDEXED_GET);
if (!indexedGet) {
this.error(
DiagnosticCode.Index_signature_is_missing_in_type_0,
expression.range, (<Class>target).internalName
);
} else {
this.error(
DiagnosticCode.Index_signature_in_type_0_only_permits_reading,
expression.range, (<Class>target).internalName
);
}
return this.module.createUnreachable();
}
elementType = indexedGet.signature.returnType;
assert(indexedSet.signature.parameterTypes.length == 2); // parser must guarantee this
elementType = indexedSet.signature.parameterTypes[1]; // 2nd parameter is the element
break;
}
// fall-through