Skip to content

Commit

Permalink
GH-518 Inherit visibility while overriding (Resolve #503)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed May 26, 2020
1 parent e2d8c50 commit 9901754
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions examples/tests/current_test.panda
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ shared class Foo : Test, IEcho {
}

// we need to mark overridden methods by the keyword
override shared static anotherEcho(String message1) {
override static anotherEcho(String message1) {
log message1
}

// we need to impl all methods
override internal test() { }
override test() { }

override public String toString() {
override String toString() {
return 'Foo'
}

Expand All @@ -218,7 +218,7 @@ internal class Entity {
}

// override native equals and name-based equality
override public PrimitiveBool equals(Object obj) {
override PrimitiveBool equals(Object obj) {
return obj is Entity && name == (obj as Entity).name
}

Expand Down Expand Up @@ -261,7 +261,7 @@ internal class Test {
}
}

override public String toString() {
override String toString() {
return 'Custom toString() in Test type #' + Int.toHexString(System.identityHashCode(this))
}

Expand Down Expand Up @@ -304,7 +304,7 @@ internal class CustomThread : Thread {
base('CustomThread')
}

override public run() {
override run() {
log 'Called in ' + Thread.currentThread().getName()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Option<Adjustment<TypeMethod>> getAdjustedArguments(String name, Expressi

@Override
public List<? extends TypeMethod> getPropertiesLike(String name) {
return super.getPropertiesLike(name, method -> super.type.getState() == State.ABSTRACT || !method.isAbstract());
return super.getPropertiesLike(name, method -> true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected BootstrapInitializer<Void> initialize(Context context, BootstrapInitia
.interceptor(new CustomPatternInterceptor())
.pattern(CustomPattern.of(
KeywordElement.create(Keywords.OVERRIDE).optional(),
VariantElement.create("visibility").content("public", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase())),
VariantElement.create("visibility").optional().content("public", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase())),
UnitElement.create("static").content("static").optional(),
TypeElement.create("type").optional().verify(new NextTokenTypeVerifier(TokenTypes.UNKNOWN)),
WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN)),
Expand Down Expand Up @@ -132,6 +132,10 @@ void verifyData(Context context, LocalCache local, @Ctx Type type, @Int Result r
"Change return type if you want to override that method or rename current method"
);
});

local.allocated("visibility", result.has("visibility") ? result.get("visibility") : existingMethod.map(TypeMethod::getVisibility).getOrElseThrow(() -> {
throw new PandaParserFailure(context, name, "Missing visibility");
}));
}

@Autowired(order = 4, cycle = GenerationCycles.TYPES_LABEL)
Expand All @@ -142,7 +146,7 @@ void declareMethod(LocalCache local, @Ctx Type type, @Int Result result, @Src("n
.name(name.getValue())
.location(scope.getSourceLocation())
.isAbstract(body == null)
.visibility(result.get("visibility"))
.visibility(local.getValue("visibility"))
.returnType(returnType)
.isStatic(result.has("static"))
.isNative(local.hasValue("native"))
Expand Down

0 comments on commit 9901754

Please sign in to comment.