From 80ccf832531f9461462b7e4494363d911612da61 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 10 Oct 2024 10:09:26 +0200 Subject: [PATCH] this fixes #2048 --- .../interpreter/result/RelationResult.java | 11 +++++++---- .../library/lang/rascal/tests/basic/Relations.rsc | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/org/rascalmpl/interpreter/result/RelationResult.java b/src/org/rascalmpl/interpreter/result/RelationResult.java index 196fec40206..76f7a205ef2 100644 --- a/src/org/rascalmpl/interpreter/result/RelationResult.java +++ b/src/org/rascalmpl/interpreter/result/RelationResult.java @@ -431,13 +431,16 @@ public Result 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()); } } diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/Relations.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/Relations.rsc index bfbae1e6403..459ef2588c4 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/basic/Relations.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/Relations.rsc @@ -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; // throws UndeclaredField + return false; +} + +test bool fieldSelectionEmpty() { + rel[int a, int b] x = {}; + return x == {}; +} \ No newline at end of file