Skip to content

Commit

Permalink
Fail compilation for property access on primitive types (#2751)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziemchawdhary-gs authored Apr 4, 2024
1 parent 6234726 commit 682df1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.RelationType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameter;
Expand Down Expand Up @@ -176,6 +177,11 @@ public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespe
}
else
{
if (inferredType instanceof PrimitiveType)
{
throw new EngineException("The property '" + property + "' can't be accessed on primitive types. Inferred primitive type is " + inferredType, sourceInformation, EngineErrorType.COMPILATION);
}

if (!(inferredType instanceof Class)) //is an enum
{
inferredType = context.pureModel.getType("meta::pure::metamodel::type::Enum");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,15 @@ public void testProjectInferenceWithClass()
" z(){test::A.all()->project([a|$a.name], ['a', 'b'])}:meta::pure::tds::TabularDataSet[1];" +
" g(){test::A.all()->project(a|$a.name, ['a', 'b'])}:meta::pure::tds::TabularDataSet[1];" +
"}");
test("Class test::A" +
"{" +
" name : String[1];" +
"}" +
"" +
"Class test::B" +
"{" +
" z(){test::A.all()->project([a|$a.name.name], ['a'])}:meta::pure::tds::TabularDataSet[1];" +
"}", "COMPILATION error at [1:91-94]: The property 'name' can't be accessed on primitive types. Inferred primitive type is String");
test("Class test::A" +
"{" +
" name : String[1];" +
Expand Down

0 comments on commit 682df1a

Please sign in to comment.