Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ test bool aliasAndADT2() {
Transitions = {<1,2,3>};
return true;
}

alias IntList = list[int];

test bool assignThroughListAlias() {
IntList values = [1, 2];
values[0] = 3;
return values == [3, 2];
}

alias trans = tuple[str, str, str];
alias block = set[trans];
Expand Down
40 changes: 20 additions & 20 deletions src/org/rascalmpl/semantics/dynamic/Assignable.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public Result<IValue> assignment(AssignableEvaluator __eval) {
throw new UninitializedVariable(this.getReceiver());
}

if (rec.getStaticType().isList()
if (rec.getStaticUnaliasedType().isList()
&& subscript.getStaticType().isInteger()) {
try {
IList list = (IList) rec.getValue();
Expand All @@ -466,42 +466,42 @@ public Result<IValue> assignment(AssignableEvaluator __eval) {
.__getValue()));
list = list.put(index, __eval.__getValue().getValue());
result = org.rascalmpl.interpreter.result.ResultFactory
.makeResult(rec.hasInferredType() ? rec.getStaticType()
.lub(list.getType()) : rec.getStaticType(), list,
.makeResult(rec.hasInferredType() ? rec.getStaticUnaliasedType()
.lub(list.getType()) : rec.getStaticUnaliasedType(), list,
__eval.__getEval());
} catch (IndexOutOfBoundsException e) {
throw org.rascalmpl.exceptions.RuntimeExceptionFactory
.indexOutOfBounds((IInteger) subscript.getValue(),
__eval.__getEval().getCurrentAST(), __eval
.__getEval().getStackTrace());
}
} else if (rec.getStaticType().isMap()) {
Type keyType = rec.getStaticType().getKeyType();
} else if (rec.getStaticUnaliasedType().isMap()) {
Type keyType = rec.getStaticUnaliasedType().getKeyType();

if (rec.hasInferredType() || subscript.getStaticType().isSubtypeOf(keyType)) {
IValue oldValue = ((IMap) rec.getValue()).get(subscript.getValue());
Result<IValue> oldResult = null;

if (oldValue != null) {
Type oldType = rec.getStaticType().getValueType();
Type oldType = rec.getStaticUnaliasedType().getValueType();
oldResult = makeResult(oldType, oldValue, __eval.getEvaluator());
oldResult.setInferredType(rec.hasInferredType());
__eval.__setValue(__eval.newResult(oldResult, __eval.__getValue()));
IMap map = ((IMap) rec.getValue()).put(subscript.getValue(), __eval.__getValue().getValue());
result = makeResult(rec.hasInferredType() ? rec.getStaticType().lub(map.getType()) : rec.getStaticType(), map, __eval.__getEval());
result = makeResult(rec.hasInferredType() ? rec.getStaticUnaliasedType().lub(map.getType()) : rec.getStaticUnaliasedType(), map, __eval.__getEval());
}
else {
// to trigger unassigned variable exception in case of a += operator
__eval.newResult(oldResult, __eval.__getValue());
IMap map = ((IMap) rec.getValue()).put(subscript.getValue(), __eval.__getValue().getValue());
result = makeResult(rec.hasInferredType() ? rec.getStaticType().lub(map.getType()) : rec.getStaticType(), map,
result = makeResult(rec.hasInferredType() ? rec.getStaticUnaliasedType().lub(map.getType()) : rec.getStaticUnaliasedType(), map,
__eval.__getEval());
}
} else {
throw new UnexpectedType(keyType, subscript.getStaticType(), this.getSubscript());
}

} else if (rec.getStaticType().isNode()
} else if (rec.getStaticUnaliasedType().isNode()
&& subscript.getStaticType().isInteger()) {
int index = ((IInteger) subscript.getValue()).intValue();
IConstructor node = (IConstructor) rec.getValue();
Expand All @@ -516,8 +516,8 @@ public Result<IValue> assignment(AssignableEvaluator __eval) {
.__getValue()));
node = node.set(index, __eval.__getValue().getValue());
result = org.rascalmpl.interpreter.result.ResultFactory
.makeResult(rec.getStaticType(), node, __eval.__getEval());
} else if (rec.getStaticType().isTuple()
.makeResult(rec.getStaticUnaliasedType(), node, __eval.__getEval());
} else if (rec.getStaticUnaliasedType().isTuple()
&& subscript.getStaticType().isInteger()) {
int index = ((IInteger) subscript.getValue()).intValue();
ITuple tuple = (ITuple) rec.getValue();
Expand All @@ -534,32 +534,32 @@ public Result<IValue> assignment(AssignableEvaluator __eval) {

tuple = tuple.set(index, __eval.__getValue().getValue());
result = org.rascalmpl.interpreter.result.ResultFactory
.makeResult(rec.getStaticType(), tuple, __eval.__getEval());
} else if (rec.getStaticType().isRelation()
.makeResult(rec.getStaticUnaliasedType(), tuple, __eval.__getEval());
} else if (rec.getStaticUnaliasedType().isRelation()
&& subscript.getStaticType().isSubtypeOf(
rec.getStaticType().getFieldType(0))) {
rec.getStaticUnaliasedType().getFieldType(0))) {
ISet rel = (ISet) rec.getValue();
IValue sub = subscript.getValue();

if (rec.getStaticType().getArity() != 2) {
throw new UnsupportedSubscript(rec.getStaticType(),
if (rec.getStaticUnaliasedType().getArity() != 2) {
throw new UnsupportedSubscript(rec.getStaticUnaliasedType(),
subscript.getStaticType(), this);
}

if (!__eval.__getValue().getStaticType().isSubtypeOf(
rec.getStaticType().getFieldType(1))) {
rec.getStaticUnaliasedType().getFieldType(1))) {
throw new UnexpectedType(
rec.getStaticType().getFieldType(1), __eval.__getValue()
rec.getStaticUnaliasedType().getFieldType(1), __eval.__getValue()
.getStaticType(), __eval.__getEval()
.getCurrentAST());
}

rel = rel.insert(__eval.__getEval().getValueFactory().tuple(
sub, __eval.__getValue().getValue()));
result = org.rascalmpl.interpreter.result.ResultFactory
.makeResult(rec.getStaticType(), rel, __eval.__getEval());
.makeResult(rec.getStaticUnaliasedType(), rel, __eval.__getEval());
} else {
throw new UnsupportedSubscript(rec.getStaticType(), subscript.getStaticType(), this);
throw new UnsupportedSubscript(rec.getStaticUnaliasedType(), subscript.getStaticType(), this);
// TODO implement other subscripts
}

Expand Down
Loading