mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Fix declaration mismatch in generated constructors (#505)
This commit is contained in:
parent
4be78147e6
commit
3b5b96f496
@ -48,8 +48,7 @@ import {
|
|||||||
SETTER_PREFIX,
|
SETTER_PREFIX,
|
||||||
LibrarySymbols,
|
LibrarySymbols,
|
||||||
CommonSymbols,
|
CommonSymbols,
|
||||||
INDEX_SUFFIX,
|
INDEX_SUFFIX
|
||||||
LIBRARY_PREFIX
|
|
||||||
} from "./common";
|
} from "./common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -147,7 +146,8 @@ import {
|
|||||||
|
|
||||||
nodeIsConstantValue,
|
nodeIsConstantValue,
|
||||||
findDecorator,
|
findDecorator,
|
||||||
FieldDeclaration
|
FieldDeclaration,
|
||||||
|
FunctionDeclaration
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -5716,10 +5716,11 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
let parameterTypes = instance.signature.parameterTypes;
|
let parameterTypes = instance.signature.parameterTypes;
|
||||||
let parameterNodes = instance.prototype.signatureNode.parameters;
|
let parameterNodes = instance.prototype.signatureNode.parameters;
|
||||||
|
assert(parameterNodes.length == parameterTypes.length);
|
||||||
let allOptionalsAreConstant = true;
|
let allOptionalsAreConstant = true;
|
||||||
for (let i = numArguments; i < maxArguments; ++i) {
|
for (let i = numArguments; i < maxArguments; ++i) {
|
||||||
let initializer = parameterNodes[i].initializer;
|
let initializer = parameterNodes[i].initializer;
|
||||||
if (!(initializer !== null && nodeIsConstantValue(initializer.kind))) {
|
if (!(initializer && nodeIsConstantValue(initializer.kind))) {
|
||||||
allOptionalsAreConstant = false;
|
allOptionalsAreConstant = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -6653,22 +6654,38 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the signature of the parent constructor if a derived class
|
// clone base constructor if a derived class
|
||||||
var baseClass = classInstance.base;
|
var baseClass = classInstance.base;
|
||||||
var signature = baseClass
|
if (baseClass) {
|
||||||
? this.ensureConstructor(baseClass, reportNode).signature
|
let baseCtor = this.ensureConstructor(baseClass, reportNode);
|
||||||
: new Signature(null, classInstance.type, classInstance.type);
|
instance = new Function(
|
||||||
|
CommonSymbols.constructor,
|
||||||
|
new FunctionPrototype(
|
||||||
|
CommonSymbols.constructor,
|
||||||
|
classInstance,
|
||||||
|
// declaration is important, i.e. to access optional parameter initializers
|
||||||
|
(<FunctionDeclaration>baseCtor.declaration).clone()
|
||||||
|
),
|
||||||
|
baseCtor.signature,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
// otherwise make a default constructor
|
||||||
|
} else {
|
||||||
|
instance = new Function(
|
||||||
|
CommonSymbols.constructor,
|
||||||
|
new FunctionPrototype(
|
||||||
|
CommonSymbols.constructor,
|
||||||
|
classInstance,
|
||||||
|
this.program.makeNativeFunctionDeclaration(CommonSymbols.constructor,
|
||||||
|
CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new Signature(null, classInstance.type, classInstance.type),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
instance = new Function(
|
|
||||||
CommonSymbols.constructor,
|
|
||||||
new FunctionPrototype(CommonSymbols.constructor, classInstance,
|
|
||||||
this.program.makeNativeFunctionDeclaration(CommonSymbols.constructor,
|
|
||||||
CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR
|
|
||||||
)
|
|
||||||
),
|
|
||||||
signature,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
instance.internalName = classInstance.internalName + INSTANCE_DELIMITER + "constructor";
|
instance.internalName = classInstance.internalName + INSTANCE_DELIMITER + "constructor";
|
||||||
instance.set(CommonFlags.COMPILED);
|
instance.set(CommonFlags.COMPILED);
|
||||||
instance.prototype.setResolvedInstance("", instance);
|
instance.prototype.setResolvedInstance("", instance);
|
||||||
@ -6677,6 +6694,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
this.currentFlow = instance.flow;
|
this.currentFlow = instance.flow;
|
||||||
|
|
||||||
// generate body
|
// generate body
|
||||||
|
var signature = instance.signature;
|
||||||
var module = this.module;
|
var module = this.module;
|
||||||
var nativeSizeType = this.options.nativeSizeType;
|
var nativeSizeType = this.options.nativeSizeType;
|
||||||
var stmts = new Array<ExpressionRef>();
|
var stmts = new Array<ExpressionRef>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user