Emit an error when trying to inline a mutable variable

This commit is contained in:
dcodeIO 2018-07-19 16:38:09 +02:00
parent fafaf423b4
commit 66cc359849
2 changed files with 20 additions and 8 deletions

View File

@ -66,7 +66,8 @@ import {
VariableLikeDeclarationStatement,
VariableStatement,
decoratorNameToKind
decoratorNameToKind,
findDecorator
} from "./ast";
import {
@ -948,7 +949,7 @@ export class Program extends DiagnosticEmitter {
Type.void, // resolved later on
declaration,
decorators
? this.checkDecorators(decorators, DecoratorFlags.NONE)
? this.checkDecorators(decorators, DecoratorFlags.INLINE)
: DecoratorFlags.NONE
);
staticField.parent = classPrototype;
@ -958,6 +959,13 @@ export class Program extends DiagnosticEmitter {
staticField.set(CommonFlags.MODULE_EXPORT);
}
if (staticField.hasDecorator(DecoratorFlags.INLINE) && !staticField.is(CommonFlags.READONLY)) {
this.error(
DiagnosticCode.Decorator_0_is_not_valid_here,
assert(findDecorator(DecoratorKind.INLINE, decorators)).range, "inline"
);
}
// instance fields are remembered until resolved
} else {
if (isInterface) {
@ -1946,6 +1954,13 @@ export class Program extends DiagnosticEmitter {
global.parent = namespace;
this.elementsLookup.set(internalName, global);
if (global.hasDecorator(DecoratorFlags.INLINE) && !global.is(CommonFlags.CONST)) {
this.error(
DiagnosticCode.Decorator_0_is_not_valid_here,
assert(findDecorator(DecoratorKind.INLINE, decorators)).range, "inline"
);
}
if (namespace) {
if (namespace.members) {
if (namespace.members.has(simpleName)) {

View File

@ -14,8 +14,7 @@ var offset: usize = startOffset;
// Memory allocator interface
@global
export function __memory_allocate(size: usize): usize {
@global export function __memory_allocate(size: usize): usize {
if (size) {
if (size > MAX_SIZE_32) unreachable();
let ptr = offset;
@ -36,10 +35,8 @@ export function __memory_allocate(size: usize): usize {
return 0;
}
@global
export function __memory_free(ptr: usize): void { /* nop */ }
@global export function __memory_free(ptr: usize): void { /* nop */ }
@global
export function __memory_reset(): void {
@global export function __memory_reset(): void {
offset = startOffset;
}