Skip to content

Commit 66cc359

Browse files
committed
Emit an error when trying to inline a mutable variable
1 parent fafaf42 commit 66cc359

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/program.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ import {
6666
VariableLikeDeclarationStatement,
6767
VariableStatement,
6868

69-
decoratorNameToKind
69+
decoratorNameToKind,
70+
findDecorator
7071
} from "./ast";
7172

7273
import {
@@ -948,7 +949,7 @@ export class Program extends DiagnosticEmitter {
948949
Type.void, // resolved later on
949950
declaration,
950951
decorators
951-
? this.checkDecorators(decorators, DecoratorFlags.NONE)
952+
? this.checkDecorators(decorators, DecoratorFlags.INLINE)
952953
: DecoratorFlags.NONE
953954
);
954955
staticField.parent = classPrototype;
@@ -958,6 +959,13 @@ export class Program extends DiagnosticEmitter {
958959
staticField.set(CommonFlags.MODULE_EXPORT);
959960
}
960961

962+
if (staticField.hasDecorator(DecoratorFlags.INLINE) && !staticField.is(CommonFlags.READONLY)) {
963+
this.error(
964+
DiagnosticCode.Decorator_0_is_not_valid_here,
965+
assert(findDecorator(DecoratorKind.INLINE, decorators)).range, "inline"
966+
);
967+
}
968+
961969
// instance fields are remembered until resolved
962970
} else {
963971
if (isInterface) {
@@ -1946,6 +1954,13 @@ export class Program extends DiagnosticEmitter {
19461954
global.parent = namespace;
19471955
this.elementsLookup.set(internalName, global);
19481956

1957+
if (global.hasDecorator(DecoratorFlags.INLINE) && !global.is(CommonFlags.CONST)) {
1958+
this.error(
1959+
DiagnosticCode.Decorator_0_is_not_valid_here,
1960+
assert(findDecorator(DecoratorKind.INLINE, decorators)).range, "inline"
1961+
);
1962+
}
1963+
19491964
if (namespace) {
19501965
if (namespace.members) {
19511966
if (namespace.members.has(simpleName)) {

std/assembly/allocator/arena.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ var offset: usize = startOffset;
1414

1515
// Memory allocator interface
1616

17-
@global
18-
export function __memory_allocate(size: usize): usize {
17+
@global export function __memory_allocate(size: usize): usize {
1918
if (size) {
2019
if (size > MAX_SIZE_32) unreachable();
2120
let ptr = offset;
@@ -36,10 +35,8 @@ export function __memory_allocate(size: usize): usize {
3635
return 0;
3736
}
3837

39-
@global
40-
export function __memory_free(ptr: usize): void { /* nop */ }
38+
@global export function __memory_free(ptr: usize): void { /* nop */ }
4139

42-
@global
43-
export function __memory_reset(): void {
40+
@global export function __memory_reset(): void {
4441
offset = startOffset;
4542
}

0 commit comments

Comments
 (0)