Skip to content

Commit

Permalink
Fix for #1256: category/extension method must be public (and static)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 8, 2021
1 parent 940303c commit 776c91f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,7 @@ public void testNothingIsUnknownWithCategories() {
" }\n" +
"} \n" +
"\n" +
"class MeCat { \n" +
"class MeCat {\n" +
" static String getVal(Me self) {\n" +
" 'val'\n" +
" }\n" +
Expand All @@ -3035,6 +3035,32 @@ public void testNothingIsUnknownWithCategories() {
"new Me().meth()");
}

@Test
public void testNonPublicCategoryMethod() {
String contents =
"class Cat { \n" +
" protected static void nope(self) {\n" +
" }\n" +
"}\n" +
"use (Cat) {\n" +
" this.nope()\n" +
"}\n";
assertUnknown(contents, "nope");
}

@Test
public void testNonStaticCategoryMethod() {
String contents =
"class Cat { \n" +
" public void nope(self) {\n" +
" }\n" +
"}\n" +
"use (Cat) {\n" +
" this.nope()\n" +
"}\n";
assertUnknown(contents, "nope");
}

@Test
public void testNonCategoryUseMethod() {
String contents =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -136,7 +136,7 @@ private static boolean isCompatibleConstantExpression(final Expression node, fin
}

private static boolean isCompatibleCategoryMethod(final MethodNode method, final ClassNode firstArgumentType, final VariableScope scope) {
if (method.isStatic()) {
if (method.isPublic() && method.isStatic()) {
Parameter[] parameters = method.getParameters();
if (parameters != null && parameters.length > 0) {
ClassNode parameterType = parameters[0].getType();
Expand Down

0 comments on commit 776c91f

Please sign in to comment.