mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8023549: Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied
Reviewed-by: jjg, vromero
This commit is contained in:
parent
cab6b226ff
commit
4cc7a55aab
5 changed files with 78 additions and 0 deletions
|
@ -2647,6 +2647,13 @@ public class Attr extends JCTree.Visitor {
|
|||
|
||||
if (that.getMode() == JCMemberReference.ReferenceMode.NEW) {
|
||||
exprType = chk.checkConstructorRefType(that.expr, exprType);
|
||||
if (!exprType.isErroneous() &&
|
||||
exprType.isRaw() &&
|
||||
that.typeargs != null) {
|
||||
log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
|
||||
diags.fragment("mref.infer.and.explicit.params"));
|
||||
exprType = types.createErrorType(exprType);
|
||||
}
|
||||
}
|
||||
|
||||
if (exprType.isErroneous()) {
|
||||
|
|
|
@ -1927,6 +1927,10 @@ compiler.misc.diamond.non.generic=\
|
|||
compiler.misc.diamond.and.explicit.params=\
|
||||
cannot use ''<>'' with explicit type parameters for constructor
|
||||
|
||||
# 0: unused
|
||||
compiler.misc.mref.infer.and.explicit.params=\
|
||||
cannot use raw constructor reference with explicit type parameters for constructor
|
||||
|
||||
# 0: type, 1: list of type
|
||||
compiler.misc.explicit.param.do.not.conform.to.bounds=\
|
||||
explicit type argument {0} does not conform to declared bound(s) {1}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.invalid.mref
|
||||
// key: compiler.misc.mref.infer.and.explicit.params
|
||||
|
||||
public class MrefInferAndExplicitParams {
|
||||
static class Foo<X> {}
|
||||
|
||||
interface Supplier<X> {
|
||||
X make();
|
||||
}
|
||||
|
||||
Supplier<Foo<String>> sfs = Foo::<Number>new;
|
||||
}
|
27
langtools/test/tools/javac/lambda/8023549/T8023549.java
Normal file
27
langtools/test/tools/javac/lambda/8023549/T8023549.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8023549
|
||||
* @summary Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied
|
||||
* @compile/fail/ref=T8023549.out -XDrawDiagnostics T8023549.java
|
||||
*/
|
||||
|
||||
public class T8023549 {
|
||||
static class Foo<X> { }
|
||||
|
||||
interface Supplier<X> {
|
||||
X make();
|
||||
}
|
||||
|
||||
interface ExtSupplier<X> extends Supplier<X> { }
|
||||
|
||||
void m1(Supplier<Foo<String>> sfs) { }
|
||||
|
||||
void m2(Supplier<Foo<String>> sfs) { }
|
||||
void m2(ExtSupplier<Foo<Integer>> sfs) { }
|
||||
|
||||
void test() {
|
||||
Supplier<Foo<String>> sfs = Foo::<Number>new;
|
||||
m1(Foo::<Number>new);
|
||||
m2(Foo::<Number>new);
|
||||
}
|
||||
}
|
5
langtools/test/tools/javac/lambda/8023549/T8023549.out
Normal file
5
langtools/test/tools/javac/lambda/8023549/T8023549.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
T8023549.java:23:37: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params)
|
||||
T8023549.java:24:12: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params)
|
||||
T8023549.java:25:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(T8023549.Supplier<T8023549.Foo<java.lang.String>>), T8023549, kindname.method, m2(T8023549.ExtSupplier<T8023549.Foo<java.lang.Integer>>), T8023549
|
||||
T8023549.java:25:12: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.mref.infer.and.explicit.params)
|
||||
4 errors
|
Loading…
Add table
Add a link
Reference in a new issue