Skip to content

Commit

Permalink
this fixes #2048
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Oct 10, 2024
1 parent 507e971 commit 80ccf83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/org/rascalmpl/interpreter/result/RelationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,16 @@ public Result<IValue> fieldSelect(Field[] selectedFields) {
fieldIndices[i] = ((IInteger) f.getFieldIndex()
.interpret(this.ctx.getEvaluator()).getValue()).intValue();
} else {
String fieldName = org.rascalmpl.interpreter.utils.Names
.name(f.getFieldName());
String fieldName = org.rascalmpl.interpreter.utils.Names.name(f.getFieldName());

if (!baseType.hasFieldNames()) {
throw new UndeclaredField(fieldName, baseType,ctx.getCurrentAST());
}

try {
fieldIndices[i] = baseType.getFieldIndex(fieldName);
} catch (UndeclaredFieldException e) {
throw new UndeclaredField(fieldName, baseType,
ctx.getCurrentAST());
throw new UndeclaredField(fieldName, baseType, ctx.getCurrentAST());
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/org/rascalmpl/library/lang/rascal/tests/basic/Relations.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ test bool tst_rangeX(rel[int, int] X) {
XR = rangeX(X, s);
return isEmpty(XR) || all(<_, b> <- XR, b notin s);
}

@expected{UndeclaredField}
@ignoreCompiler{The checker would detect this}
test bool fieldSelectionNoFields() {
x = {};
x<name>; // throws UndeclaredField
return false;
}

test bool fieldSelectionEmpty() {
rel[int a, int b] x = {};
return x<b,a> == {};
}

0 comments on commit 80ccf83

Please sign in to comment.