提交 5f7203a8 编写于 作者: V vromero

8023549: Compiler emitting spurious errors when constructor reference type is...

8023549: Compiler emitting spurious errors when constructor reference type is inferred and explicit type arguments are supplied
Reviewed-by: jjg, vromero
Contributed-by: maurizio.cimadamore@oracle.com
上级 0ee6bd7e
......@@ -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}
......
/*
* 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;
}
/*
* @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);
}
}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册