diff options
author | Kalyan Prasad Tatavarthi | 2021-02-17 07:04:15 +0000 |
---|---|---|
committer | Kalyan Prasad Tatavarthi | 2021-02-17 08:21:03 +0000 |
commit | 33f60d3da79a0ae0b5266c2c7f357a3f7fdb6519 (patch) | |
tree | 22dca6596b03e386316d799d8d4bd3a12bea3123 | |
parent | 0c500895907bfebb43796d0991bc9f45d7e18834 (diff) | |
download | eclipse.jdt.core-33f60d3da79a0ae0b5266c2c7f357a3f7fdb6519.tar.gz eclipse.jdt.core-33f60d3da79a0ae0b5266c2c7f357a3f7fdb6519.tar.xz eclipse.jdt.core-33f60d3da79a0ae0b5266c2c7f357a3f7fdb6519.zip |
Bug 566758 - Type parameter of enclosing method should not be referencedY20210218-1000
in local static interface
Change-Id: I34a523369f4d15e4deb2785b64658f29ec08f1d3
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
2 files changed, 38 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java index fc67670a8d..9f39c36104 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java @@ -7811,4 +7811,30 @@ public void test476281a() { }, "Success"); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=566758 +public void test566758() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " <T> void m(T t) {\n" + + " interface Y {\n" + + " T foo(); // T should not be allowed\n" + + " }\n" + + " }\n" + + " \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " T foo(); // T should not be allowed\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n", + null, + true); +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java index c61885761e..bb152b9403 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2020 IBM Corporation and others. + * Copyright (c) 2000, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8,6 +8,10 @@ * * SPDX-License-Identifier: EPL-2.0 * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann - Contributions for @@ -3301,6 +3305,7 @@ public abstract class Scope { MethodScope methodScope = null; ReferenceBinding foundType = null; boolean insideStaticContext = false; + boolean insideClassContext = false; boolean insideTypeAnnotation = false; if ((mask & Binding.TYPE) == 0) { Scope next = scope; @@ -3316,8 +3321,12 @@ public abstract class Scope { if (methodDecl != null) { if (methodDecl.binding != null) { TypeVariableBinding typeVariable = methodDecl.binding.getTypeVariable(name); - if (typeVariable != null) + if (typeVariable != null) { + if (insideStaticContext && insideClassContext) { + return new ProblemReferenceBinding(new char[][]{name}, typeVariable, ProblemReasons.NonStaticReferenceInStaticContext); + } return typeVariable; + } } else { // use the methodDecl's typeParameters to handle problem cases when the method binding doesn't exist TypeParameter[] params = methodDecl.typeParameters(); @@ -3388,6 +3397,7 @@ public abstract class Scope { return typeVariable; } insideStaticContext |= sourceType.isStatic(); + insideClassContext = true; insideTypeAnnotation = false; if (CharOperation.equals(sourceType.sourceName, name)) { if (foundType != null && TypeBinding.notEquals(foundType, sourceType) && foundType.problemId() != ProblemReasons.NotVisible) |