Commit b402d6a5 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - class type cannot be the contained value of an any type value (issue #428)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 74e53504
......@@ -70,6 +70,7 @@ public final class Anytype_Type extends Type {
private static final String ONEFIELDEXPECTED = "A template for anytype type must contain exactly one selected field";
private static final String ANYTYPEEXPECTED = "Anytype value was expected for type `{0}''";
private static final String NONEXISTENTUNION = "Reference to a non-existent field `{0}'' in anytype value for type `{1}''";
private static final String CLASSCANNOTBECONTAINED = "Class type cannot be the contained value of an any type value";
private static final String NOCOMPATIBLEFIELD = "Type anytype `{0}'' doesn''t have any field compatible with `{1}''";
private static final String NOTCOMPATIBLEANYTYPE = "Type anytype is compatible only with other anytype types";
......@@ -676,6 +677,12 @@ public final class Anytype_Type extends Type {
if (fieldType == null) {
return null;
}
if (fieldType instanceof Referenced_Type) {
if (fieldType.getTypeRefdLast(timestamp) instanceof Class_Type) {
subreference.getLocation().reportSemanticError(CLASSCANNOTBECONTAINED);
return null;
}
}
final Expected_Value_type internalExpectation =
(expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE) ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment