Skip to content

Commit

Permalink
Merge 1991b7b into 2e9bcc6
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed Apr 7, 2020
2 parents 2e9bcc6 + 1991b7b commit e73d7a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 18 additions & 2 deletions core-lib/TestSuite/RegressionTests.ns
Expand Up @@ -26,19 +26,35 @@ class RegressionTests usingPlatform: platform testFramework: minitest = (
class B = ()( public foo = ( ^ 2 ) ) : ( public bar = ( ^ 2 ))

make: cls = ( ^ cls new )

bar: cls = ( ^ cls bar )

public testMake = (
self assert: (make: A) foo equals: 1.
self assert: (make: B) foo equals: 2.
self assert: (make: A) foo equals: 1.
)

public testClassMethod = (
self assert: (bar: A) equals: 1.
self assert: (bar: B) equals: 2.
self assert: (bar: A) equals: 1.
)
) : ( TEST_CONTEXT = () )

public class VariableAccessInLocalDefinition = TestContext ()(
public testSelfInBlock = (
| var = [ self ] value. |
self assert: var is: self.
)

public returnSelfFromBlock = (
| var = [ ^ self ] value. |
^ #error
)

public testReturnSelfFromBlock = (
self assert: returnSelfFromBlock is: self
)
) : ( TEST_CONTEXT = () )
)
20 changes: 18 additions & 2 deletions src/som/interpreter/LexicalScope.java
Expand Up @@ -15,6 +15,7 @@
import som.compiler.MixinBuilder.MixinDefinitionId;
import som.compiler.MixinDefinition;
import som.compiler.Variable;
import som.compiler.Variable.Internal;
import som.interpreter.nodes.dispatch.Dispatchable;
import som.vmobjects.SSymbol;

Expand Down Expand Up @@ -193,8 +194,18 @@ public MethodScope(final FrameDescriptor frameDescriptor, final LexicalScope out

public void setVariables(final Variable[] variables) {
assert variables != null : "variables are expected to be != null once set";
assert this.variables == null;
this.variables = variables;
assert this.variables == null
|| (this.variables.length == 1 && this.variables[0] instanceof Internal);
if (this.variables == null) {
this.variables = variables;
} else {
Variable internal = this.variables[0];
this.variables = new Variable[variables.length + 1];
for (int i = 0; i < variables.length; i += 1) {
this.variables[i] = variables[i];
}
this.variables[variables.length] = internal;
}
}

/**
Expand All @@ -207,6 +218,11 @@ public boolean hasVariables() {
}

public void addVariable(final Variable var) {
if (variables == null) {
variables = new Variable[] {var};
return;
}

int length = variables.length;
variables = Arrays.copyOf(variables, length + 1);
variables[length] = var;
Expand Down

0 comments on commit e73d7a6

Please sign in to comment.