From c98ecf567085bde6bc1ad772c6a4c2d57494c0ef Mon Sep 17 00:00:00 2001 From: mmews Date: Thu, 11 Jul 2024 14:14:28 +0200 Subject: [PATCH] fix --- .../utils/StructuralTypingComputer.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/typesystem/utils/StructuralTypingComputer.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/typesystem/utils/StructuralTypingComputer.java index 264d465782..1d8dfe1d5b 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/typesystem/utils/StructuralTypingComputer.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/typesystem/utils/StructuralTypingComputer.java @@ -380,8 +380,9 @@ private void checkMembers(TypeRef leftTypeRef, StructuralMembersTriple triple, S + " failed: readable field requires a readable field or a getter in subtype."); } } - } break; + } + // For any ~w~ right members. case STRUCTURAL_WRITE_ONLY_FIELDS: { @@ -404,8 +405,8 @@ private void checkMembers(TypeRef leftTypeRef, StructuralMembersTriple triple, S + " failed: writable field requires a writable field or a setter in subtype."); } } - } break; + } // For any ~i~ right members. case STRUCTURAL_FIELD_INITIALIZER: { @@ -429,28 +430,29 @@ private void checkMembers(TypeRef leftTypeRef, StructuralMembersTriple triple, S + " failed: non-optional writable field requires a readable field or a getter in subtype."); } } - } break; + } - default: { + default: // If the left member is ~r~, ~w~ and/or ~i~ type. if (STRUCTURAL_READ_ONLY_FIELDS == leftStrategy || STRUCTURAL_WRITE_ONLY_FIELDS == leftStrategy || STRUCTURAL_FIELD_INITIALIZER == leftStrategy) { + // If right is writable field, a getter/setter pair is mandatory on the left. if (isWriteableField(rightMember)) { if (!isGetterSetterPair(leftMember, leftOtherAccessor)) { info.wrongMembers.add(rightMember.getName() + " failed: writable field requires a getter/setter pair in subtype."); } - } + } else // If right is readable, we require an explicit getter. if (READABLE_FIELDS_PREDICATE.apply(rightMember)) { if (!(GETTERS_PREDICATE.apply(leftMember) || GETTERS_PREDICATE.apply(leftOtherAccessor))) { info.wrongMembers .add(rightMember.getName() + " failed: read-only field requires a getter in subtype."); } - } + } else // If there is a setter on the right, then we need a setter on the left. if (SETTERS_PREDICATE.apply(rightMember)) { if (!(SETTERS_PREDICATE.apply(leftMember) || SETTERS_PREDICATE.apply(leftOtherAccessor))) { @@ -483,8 +485,9 @@ private void checkMembers(TypeRef leftTypeRef, StructuralMembersTriple triple, S } } + break; } - } + } /** Returns with {@code true} iff the the arguments are a getter-setter accessor pair. */