提交 54914184 编写于 作者: L lana

Merge

......@@ -1146,29 +1146,6 @@ public class Type implements PrimitiveType {
return types.subst(qtype, tvars, actuals);
}
/**
* Kind of type-constraint derived during type inference
*/
public enum ConstraintKind {
/**
* upper bound constraint (a type variable must be instantiated
* with a type T, where T is a subtype of all the types specified by
* its EXTENDS constraints).
*/
EXTENDS,
/**
* lower bound constraint (a type variable must be instantiated
* with a type T, where T is a supertype of all the types specified by
* its SUPER constraints).
*/
SUPER,
/**
* equality constraint (a type variable must be instantiated to the type
* specified by its EQUAL constraint.
*/
EQUAL;
}
/**
* Get the type-constraints of a given kind for a given type-variable of
* this ForAll type. Subclasses should override in order to return more
......@@ -1178,7 +1155,7 @@ public class Type implements PrimitiveType {
* @param ck the constraint kind to be retrieved
* @return the list of types specified by the selected constraint
*/
public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
public List<Type> undetvars() {
return List.nil();
}
......@@ -1220,6 +1197,7 @@ public class Type implements PrimitiveType {
public static class UndetVar extends DelegatedType {
public List<Type> lobounds = List.nil();
public List<Type> hibounds = List.nil();
public List<Type> eq = List.nil();
public Type inst = null;
@Override
......
......@@ -326,11 +326,6 @@ public class Types {
else if (t.tag == TYPEVAR) {
return isSubtypeUnchecked(t.getUpperBound(), s, warn);
}
else if (s.tag == UNDETVAR) {
UndetVar uv = (UndetVar)s;
if (uv.inst != null)
return isSubtypeUnchecked(t, uv.inst, warn);
}
else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
......@@ -515,9 +510,6 @@ public class Types {
return false;
}
if (t.inst != null)
return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
t.hibounds = t.hibounds.prepend(s);
return true;
}
......@@ -586,8 +578,6 @@ public class Types {
undet.qtype == s ||
s.tag == ERROR ||
s.tag == BOT) return true;
if (undet.inst != null)
return isSubtype(s, undet.inst);
undet.lobounds = undet.lobounds.prepend(s);
return true;
}
......@@ -733,18 +723,8 @@ public class Types {
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
return true;
if (t.inst != null)
return visit(t.inst, s);
t.eq = t.eq.prepend(s);
t.inst = fromUnknownFun.apply(s);
for (List<Type> l = t.lobounds; l.nonEmpty(); l = l.tail) {
if (!isSubtype(l.head, t.inst))
return false;
}
for (List<Type> l = t.hibounds; l.nonEmpty(); l = l.tail) {
if (!isSubtype(t.inst, l.head))
return false;
}
return true;
}
......@@ -779,23 +759,11 @@ public class Types {
case UNBOUND: //similar to ? extends Object
case EXTENDS: {
Type bound = upperBound(s);
// We should check the new upper bound against any of the
// undetvar's lower bounds.
for (Type t2 : undetvar.lobounds) {
if (!isSubtype(t2, bound))
return false;
}
undetvar.hibounds = undetvar.hibounds.prepend(bound);
break;
}
case SUPER: {
Type bound = lowerBound(s);
// We should check the new lower bound against any of the
// undetvar's lower bounds.
for (Type t2 : undetvar.hibounds) {
if (!isSubtype(bound, t2))
return false;
}
undetvar.lobounds = undetvar.lobounds.prepend(bound);
break;
}
......
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2012, 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
......@@ -1798,92 +1798,126 @@ public class JavacParser implements Parser {
*/
@SuppressWarnings("fallthrough")
List<JCStatement> blockStatements() {
//todo: skip to anchor on error(?)
int lastErrPos = -1;
//todo: skip to anchor on error(?)
ListBuffer<JCStatement> stats = new ListBuffer<JCStatement>();
while (true) {
int pos = token.pos;
switch (token.kind) {
case RBRACE: case CASE: case DEFAULT: case EOF:
List<JCStatement> stat = blockStatement();
if (stat.isEmpty()) {
return stats.toList();
case LBRACE: case IF: case FOR: case WHILE: case DO: case TRY:
case SWITCH: case SYNCHRONIZED: case RETURN: case THROW: case BREAK:
case CONTINUE: case SEMI: case ELSE: case FINALLY: case CATCH:
stats.append(parseStatement());
break;
case MONKEYS_AT:
case FINAL: {
String dc = token.comment(CommentStyle.JAVADOC);
JCModifiers mods = modifiersOpt();
if (token.kind == INTERFACE ||
token.kind == CLASS ||
allowEnums && token.kind == ENUM) {
stats.append(classOrInterfaceOrEnumDeclaration(mods, dc));
} else {
JCExpression t = parseType();
stats.appendList(variableDeclarators(mods, t,
new ListBuffer<JCStatement>()));
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
storeEnd(stats.elems.last(), token.endPos);
accept(SEMI);
} else {
if (token.pos <= endPosTable.errorEndPos) {
skip(false, true, true, true);
}
break;
stats.addAll(stat);
}
case ABSTRACT: case STRICTFP: {
String dc = token.comment(CommentStyle.JAVADOC);
JCModifiers mods = modifiersOpt();
stats.append(classOrInterfaceOrEnumDeclaration(mods, dc));
}
}
/*
* This method parses a statement treating it as a block, relaxing the
* JLS restrictions, allows us to parse more faulty code, doing so
* enables us to provide better and accurate diagnostics to the user.
*/
JCStatement parseStatementAsBlock() {
int pos = token.pos;
List<JCStatement> stats = blockStatement();
if (stats.isEmpty()) {
JCErroneous e = F.at(pos).Erroneous();
error(e, "illegal.start.of.stmt");
return F.at(pos).Exec(e);
} else {
JCStatement first = stats.head;
String error = null;
switch (first.getTag()) {
case CLASSDEF:
error = "class.not.allowed";
break;
}
case INTERFACE:
case CLASS:
String dc = token.comment(CommentStyle.JAVADOC);
stats.append(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
case VARDEF:
error = "variable.not.allowed";
break;
case ENUM:
case ASSERT:
if (allowEnums && token.kind == ENUM) {
error(token.pos, "local.enum");
dc = token.comment(CommentStyle.JAVADOC);
stats.append(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
break;
} else if (allowAsserts && token.kind == ASSERT) {
stats.append(parseStatement());
break;
}
/* fall through to default */
default:
Token prevToken = token;
JCExpression t = term(EXPR | TYPE);
if (token.kind == COLON && t.hasTag(IDENT)) {
nextToken();
JCStatement stat = parseStatement();
stats.append(F.at(pos).Labelled(prevToken.name(), stat));
} else if ((lastmode & TYPE) != 0 &&
(token.kind == IDENTIFIER ||
token.kind == ASSERT ||
token.kind == ENUM)) {
pos = token.pos;
JCModifiers mods = F.at(Position.NOPOS).Modifiers(0);
F.at(pos);
stats.appendList(variableDeclarators(mods, t,
new ListBuffer<JCStatement>()));
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
storeEnd(stats.elems.last(), token.endPos);
accept(SEMI);
} else {
// This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon
stats.append(to(F.at(pos).Exec(checkExprStat(t))));
accept(SEMI);
}
}
if (error != null) {
error(first, error);
List<JCBlock> blist = List.of(F.at(first.pos).Block(0, stats));
return toP(F.at(pos).Exec(F.at(first.pos).Erroneous(blist)));
}
return first;
}
}
// error recovery
if (token.pos == lastErrPos)
@SuppressWarnings("fallthrough")
List<JCStatement> blockStatement() {
//todo: skip to anchor on error(?)
int pos = token.pos;
switch (token.kind) {
case RBRACE: case CASE: case DEFAULT: case EOF:
return List.nil();
case LBRACE: case IF: case FOR: case WHILE: case DO: case TRY:
case SWITCH: case SYNCHRONIZED: case RETURN: case THROW: case BREAK:
case CONTINUE: case SEMI: case ELSE: case FINALLY: case CATCH:
return List.of(parseStatement());
case MONKEYS_AT:
case FINAL: {
String dc = token.comment(CommentStyle.JAVADOC);
JCModifiers mods = modifiersOpt();
if (token.kind == INTERFACE ||
token.kind == CLASS ||
allowEnums && token.kind == ENUM) {
return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
} else {
JCExpression t = parseType();
ListBuffer<JCStatement> stats =
variableDeclarators(mods, t, new ListBuffer<JCStatement>());
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
storeEnd(stats.elems.last(), token.endPos);
accept(SEMI);
return stats.toList();
if (token.pos <= endPosTable.errorEndPos) {
skip(false, true, true, true);
lastErrPos = token.pos;
}
}
case ABSTRACT: case STRICTFP: {
String dc = token.comment(CommentStyle.JAVADOC);
JCModifiers mods = modifiersOpt();
return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
}
case INTERFACE:
case CLASS:
String dc = token.comment(CommentStyle.JAVADOC);
return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
case ENUM:
case ASSERT:
if (allowEnums && token.kind == ENUM) {
error(token.pos, "local.enum");
dc = token.comment(CommentStyle.JAVADOC);
return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
} else if (allowAsserts && token.kind == ASSERT) {
return List.of(parseStatement());
}
/* fall through to default */
default:
Token prevToken = token;
JCExpression t = term(EXPR | TYPE);
if (token.kind == COLON && t.hasTag(IDENT)) {
nextToken();
JCStatement stat = parseStatement();
return List.<JCStatement>of(F.at(pos).Labelled(prevToken.name(), stat));
} else if ((lastmode & TYPE) != 0 &&
(token.kind == IDENTIFIER ||
token.kind == ASSERT ||
token.kind == ENUM)) {
pos = token.pos;
JCModifiers mods = F.at(Position.NOPOS).Modifiers(0);
F.at(pos);
ListBuffer<JCStatement> stats =
variableDeclarators(mods, t, new ListBuffer<JCStatement>());
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
storeEnd(stats.elems.last(), token.endPos);
accept(SEMI);
return stats.toList();
} else {
// This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon
JCExpressionStatement expr = to(F.at(pos).Exec(checkExprStat(t)));
accept(SEMI);
return List.<JCStatement>of(expr);
}
}
}
......@@ -1917,11 +1951,11 @@ public class JavacParser implements Parser {
case IF: {
nextToken();
JCExpression cond = parExpression();
JCStatement thenpart = parseStatement();
JCStatement thenpart = parseStatementAsBlock();
JCStatement elsepart = null;
if (token.kind == ELSE) {
nextToken();
elsepart = parseStatement();
elsepart = parseStatementAsBlock();
}
return F.at(pos).If(cond, thenpart, elsepart);
}
......@@ -1938,7 +1972,7 @@ public class JavacParser implements Parser {
accept(COLON);
JCExpression expr = parseExpression();
accept(RPAREN);
JCStatement body = parseStatement();
JCStatement body = parseStatementAsBlock();
return F.at(pos).ForeachLoop(var, expr, body);
} else {
accept(SEMI);
......@@ -1946,19 +1980,19 @@ public class JavacParser implements Parser {
accept(SEMI);
List<JCExpressionStatement> steps = token.kind == RPAREN ? List.<JCExpressionStatement>nil() : forUpdate();
accept(RPAREN);
JCStatement body = parseStatement();
JCStatement body = parseStatementAsBlock();
return F.at(pos).ForLoop(inits, cond, steps, body);
}
}
case WHILE: {
nextToken();
JCExpression cond = parExpression();
JCStatement body = parseStatement();
JCStatement body = parseStatementAsBlock();
return F.at(pos).WhileLoop(cond, body);
}
case DO: {
nextToken();
JCStatement body = parseStatement();
JCStatement body = parseStatementAsBlock();
accept(WHILE);
JCExpression cond = parExpression();
JCDoWhileLoop t = to(F.at(pos).DoLoop(body, cond));
......
......@@ -196,6 +196,9 @@ compiler.err.catch.without.try=\
compiler.err.clash.with.pkg.of.same.name=\
{0} {1} clashes with package of same name
compiler.err.class.not.allowed=\
class, interface or enum declaration not allowed here
compiler.err.const.expr.req=\
constant expression required
......@@ -385,6 +388,9 @@ compiler.err.illegal.qual.not.icls=\
compiler.err.illegal.start.of.expr=\
illegal start of expression
compiler.err.illegal.start.of.stmt=\
illegal start of statement
compiler.err.illegal.start.of.type=\
illegal start of type
......@@ -446,6 +452,9 @@ compiler.err.invalid.meth.decl.ret.type.req=\
compiler.err.varargs.and.old.array.syntax=\
legacy array notation not allowed on variable-arity parameter
compiler.err.variable.not.allowed=\
variable declaration not allowed here
# 0: name
compiler.err.label.already.in.use=\
label {0} already in use
......@@ -1574,9 +1583,6 @@ compiler.misc.undetermined.type=\
cannot infer type arguments for {0}\n\
reason: {1}
compiler.misc.type.variable.has.undetermined.type=\
type variable {0} has undetermined type
# 0: type, 1: list of type
compiler.misc.no.unique.maximal.instance.exists=\
no unique maximal instance exists for type variable {0} with upper bounds {1}
......@@ -1604,10 +1610,22 @@ compiler.misc.infer.varargs.argument.mismatch=\
no instance(s) of type variable(s) {0} exist so that argument type {1} conforms to vararg element type {2}
# 0: type, 1: list of type
compiler.misc.inferred.do.not.conform.to.bounds=\
inferred type does not conform to declared bound(s)\n\
compiler.misc.inferred.do.not.conform.to.upper.bounds=\
inferred type does not conform to upper bound(s)\n\
inferred: {0}\n\
upper bound(s): {1}
# 0: type, 1: list of type
compiler.misc.inferred.do.not.conform.to.lower.bounds=\
inferred type does not conform to lower bound(s)\n\
inferred: {0}\n\
bound(s): {1}
lower bound(s): {1}
# 0: type, 1: list of type
compiler.misc.inferred.do.not.conform.to.eq.bounds=\
inferred type does not conform to equality constraint(s)\n\
inferred: {0}\n\
equality constraints(s): {1}
# 0: symbol
compiler.misc.diamond=\
......@@ -2033,9 +2051,16 @@ compiler.misc.where.typevar=\
# compact where clause for type variable: contains the kindname ({2}) and location ({3})
# in which the typevar has been declared
# 0: type, 1: list of type, 2: symbol kind, 3: symbol
compiler.misc.where.typevar.1=\
{0} declared in {2} {3}
# where clause for fresh type variable: contains upper bound(s) ('extends {1}').
# Since a fresh type-variable is synthetic - there's no location/kindname here.
# 0: type, 1: list of type
compiler.misc.where.fresh.typevar=\
{0} extends {1}
# where clause for type variable: contains all the upper bound(s) ('extends {1}')
# of this intersection type
# 0: type, 1: list of type
......
......@@ -540,13 +540,22 @@ public class RichDiagnosticFormatter extends
bounds.head.tag == NONE ||
bounds.head.tag == ERROR;
JCDiagnostic d = diags.fragment("where.typevar" +
if ((t.tsym.flags() & SYNTHETIC) == 0) {
//this is a true typevar
JCDiagnostic d = diags.fragment("where.typevar" +
(boundErroneous ? ".1" : ""), t, bounds,
Kinds.kindName(t.tsym.location()), t.tsym.location());
whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
symbolPreprocessor.visit(t.tsym.location(), null);
visit(bounds);
whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
symbolPreprocessor.visit(t.tsym.location(), null);
visit(bounds);
} else {
Assert.check(!boundErroneous);
//this is a fresh (synthetic) tvar
JCDiagnostic d = diags.fragment("where.fresh.typevar", t, bounds);
whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
visit(bounds);
}
}
return null;
}
......
T6722234b.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, List<T>,List<T>, List<compiler.misc.type.captureof: 1, ? extends T6722234b>,List<compiler.misc.type.captureof: 2, ? extends T6722234b>, kindname.class, T6722234b, (compiler.misc.infer.no.conforming.assignment.exists: T, List<compiler.misc.type.captureof: 2, ? extends T6722234b>, List<T>)
T6722234b.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, List<T>,List<T>, List<compiler.misc.type.captureof: 1, ? extends T6722234b>,List<compiler.misc.type.captureof: 2, ? extends T6722234b>, kindname.class, T6722234b, (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 2, ? extends T6722234b, compiler.misc.type.captureof: 2, ? extends T6722234b,compiler.misc.type.captureof: 1, ? extends T6722234b)
1 error
T6722234b.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, List<T>,List<T>, List<compiler.misc.captured.type: 1>,List<compiler.misc.captured.type: 2>, kindname.class, T6722234b, (compiler.misc.infer.no.conforming.assignment.exists: T, List<compiler.misc.captured.type: 2>, List<T>)
T6722234b.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, List<T>,List<T>, List<compiler.misc.captured.type: 1>,List<compiler.misc.captured.type: 2>, kindname.class, T6722234b, (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.captured.type: 2, compiler.misc.captured.type: 2,compiler.misc.captured.type: 1)
- compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, Object, kindname.method, <T>m(List<T>,List<T>))}
- compiler.misc.where.description.captured.1: compiler.misc.captured.type: 1,compiler.misc.captured.type: 2,{(compiler.misc.where.captured.1: compiler.misc.captured.type: 1, T6722234b, compiler.misc.type.null, ? extends T6722234b),(compiler.misc.where.captured.1: compiler.misc.captured.type: 2, T6722234b, compiler.misc.type.null, ? extends T6722234b)}
1 error
T6799605.java:17:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.inferred.do.not.conform.to.bounds: compiler.misc.type.captureof: 1, ?, T6799605<compiler.misc.type.captureof: 1, ?>))}
T6799605.java:18:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.no.conforming.assignment.exists: T, T6799605<compiler.misc.type.captureof: 2, ?>, T6799605<T>)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch))}
T6799605.java:19:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,T6799605<compiler.misc.type.captureof: 3, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.no.conforming.assignment.exists: T, T6799605<compiler.misc.type.captureof: 2, ?>, T6799605<T>)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch))}
T6799605.java:17:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.inferred.do.not.conform.to.upper.bounds: compiler.misc.type.captureof: 1, ?, T6799605<compiler.misc.type.captureof: 1, ?>))}
T6799605.java:18:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 2, ?, compiler.misc.type.captureof: 2, ?,compiler.misc.type.captureof: 1, ?)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch))}
T6799605.java:19:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,T6799605<compiler.misc.type.captureof: 3, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 3, ?, compiler.misc.type.captureof: 3, ?,compiler.misc.type.captureof: 2, ?,compiler.misc.type.captureof: 1, ?)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch))}
3 errors
T7123100a.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z
T7123100a.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), E, Z
- compiler.err.warnings.and.werror
1 error
1 warning
/*
* Copyright (c) 2012, 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.
*/
/*
* @test
* @bug 7157626
* @summary Test major version for all legal combinations for -source and -target
* @author sgoel
*
*/
import java.io.*;
import java.nio.*;
import java.util.*;
import java.util.regex.*;
public class ClassVersionChecker {
int errors;
String[] jdk = {"","1.2","1.3","1.4","1.5","1.6","1.7","1.8"};
File javaFile = null;
public static void main(String[] args) throws Throwable {
new ClassVersionChecker().run();
}
void run() throws Exception {
writeTestFile();
/* Rules applicable for -source and -target combinations
* 1. If both empty, version num is for 1.7
* 2. If source is not empty and target is empty, version is based on source
* 3. If both non-empty, version is based on target
*/
/* -source (0=>empty,1=>1.2,...) X -target (0=>empty,1=>1.2,...)
* ver[0][0] => no -source or -target was given
* -1 => invalid combinations
*/
int[][] ver =
{{51, -1, -1, -1, -1, -1, -1, -1},
{48, 46, 47, 48, 49, 50, 51, 51},
{48, 46, 47, 48, 49, 50, 51, 51},
{48, -1, -1, 48, 49, 50, 51, 51},
{51, -1, -1, -1, 49, 50, 51, 51},
{51, -1, -1, -1, -1, 50, 51, 51},
{51, -1, -1, -1, -1, -1, 51, 51},
{51, -1, -1, -1, -1, -1, -1, 51}};
// Loop to run all possible combinations of source/target values
for (int i = 0; i< ver.length; i++) {
for (int j = 0 ; j< ver[i].length; j++) {
if(ver[i][j] != -1) {
logMsg("Index values for i = " + i + " j = " + j);
logMsg("Running for src = " + jdk[i] + " target = "+jdk[j] +" expected = " + ver[i][j]);
test(i,j, ver[i][j]);
}
}
}
if (errors > 0)
throw new Exception(errors + " errors found");
}
void test (int i, int j, int expected) {
File classFile = compileTestFile(i, j, javaFile);
short majorVer = getMajorVersion(classFile);
checkVersion(majorVer, expected);
}
void writeTestFile() throws IOException {
javaFile = new File("Test.java");
try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(javaFile)));) {
out.println("class Test { ");
out.println(" public void foo() { }");
out.println("}");
} catch (IOException ioe) {
error("IOException while creating Test.java" + ioe);
}
}
File compileTestFile(int i , int j, File f) {
int rc = -1;
// Src and target are empty
if (i == 0 && j == 0 ) {
rc = compile("-g", f.getPath());
} else if( j == 0 ) { // target is empty
rc = compile("-source", jdk[i], "-g", f.getPath());
} else {
rc = compile("-source", jdk[i], "-target", jdk[j], "-g", f.getPath());
}
if (rc != 0)
throw new Error("compilation failed. rc=" + rc);
String path = f.getPath();
return new File(path.substring(0, path.length() - 5) + ".class");
}
int compile(String... args) {
return com.sun.tools.javac.Main.compile(args);
}
void logMsg (String str) {
System.out.println(str);
}
short getMajorVersion(File f) {
List<String> args = new ArrayList<String>();
short majorVer = 0;
try(DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(f)));) {
in.readInt();
in.readShort();
majorVer = in.readShort();
System.out.println("major version:" + majorVer);
} catch (IOException e) {
error("IOException while reading Test.class" + e);
}
return majorVer;
}
void checkVersion(short majorVer, int expected) {
if (majorVer != expected ) {
error("versions did not match, Expected: " + expected + "Got: " + majorVer);
}
}
void error(String msg) {
System.out.println("error: " + msg);
errors++;
}
}
......@@ -78,7 +78,6 @@ compiler.misc.type.captureof
compiler.misc.type.captureof.1
compiler.misc.type.none
compiler.misc.type.req.exact
compiler.misc.type.variable.has.undetermined.type
compiler.misc.unable.to.access.file # ClassFile
compiler.misc.undecl.type.var # ClassReader
compiler.misc.unicode.str.not.supported # ClassReader
......
......@@ -23,7 +23,7 @@
// key: compiler.err.prob.found.req.1
// key: compiler.misc.cant.apply.diamond.1
// key: compiler.misc.infer.no.conforming.instance.exists
// key: compiler.misc.no.conforming.assignment.exists
// key: compiler.misc.diamond
class CantApplyDiamond1<X> {
......
/*
* Copyright (c) 2012, 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.illegal.start.of.stmt
// key: compiler.err.expected3
class IllegalStartOfStmt {
void m() {
if (true) }
}
}
......@@ -25,9 +25,9 @@
// key: compiler.err.prob.found.req.1
class IncompatibleTypes1<V> {
<T extends Integer & Runnable> IncompatibleTypes1<T> m() {
<T> IncompatibleTypes1<Integer> m() {
return null;
}
IncompatibleTypes1<? super String> o = m();
IncompatibleTypes1<? extends String> o = m();
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
......@@ -21,15 +21,13 @@
* questions.
*/
// key: compiler.misc.inferred.do.not.conform.to.bounds
// key: compiler.err.cant.apply.diamond.1
// key: compiler.misc.diamond
// key: compiler.err.cant.apply.symbol.1
// key: compiler.misc.infer.no.conforming.assignment.exists
class InferredDoNotConformToBounds {
static class SuperFoo<X> {}
static class Foo<X extends Number> extends SuperFoo<X> {
Foo(X x) {}
}
import java.util.*;
SuperFoo<String> sf1 = new Foo<>("");
class InferNoConformingAssignment {
<X extends Number> List<X> m(String s) { return null; }
{ this.m(1); }
}
/*
* Copyright (c) 2012, 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.cant.apply.symbol.1
// key: compiler.misc.inferred.do.not.conform.to.eq.bounds
import java.util.*;
class InferredDoNotConformToEq {
<X> void m(List<X> lx1, List<X> lx2) {}
{ this.m(Arrays.asList(""), Arrays.asList(1)); }
}
/*
* Copyright (c) 2012, 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.misc.invalid.inferred.types
// key: compiler.err.prob.found.req.1
// key: compiler.misc.inferred.do.not.conform.to.lower.bounds
import java.util.*;
class InferredDoNotConformToLower {
<X extends Number> List<X> m() { return null; }
{ List<? super String> lss = this.m(); }
}
/*
* Copyright (c) 2012, 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.cant.apply.symbol.1
// key: compiler.misc.inferred.do.not.conform.to.upper.bounds
import java.util.*;
class InferredDoNotConformToUpper {
<X> void m(X x, List<? super X> lx) {}
{ this.m("", Arrays.asList(1)); }
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2012, 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
......@@ -23,17 +23,15 @@
// key: compiler.err.prob.found.req.1
// key: compiler.misc.invalid.inferred.types
// key: compiler.misc.inferred.do.not.conform.to.bounds
// key: compiler.misc.inferred.do.not.conform.to.upper.bounds
import java.util.*;
class InvalidInferredTypes {
<T extends List<? super T>> T makeList() {
return null;
}
<S extends String> List<S> m() { return null; }
public void test() {
List<? super String> l = makeList();
void test() {
List<Integer> li = m();
}
}
/*
* Copyright (c) 2012, 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.class.not.allowed
class NotAllowedClass {
void t1() {
if (true)
class X {}
}
}
/*
* Copyright (c) 2012, 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.variable.not.allowed
class NotAllowedVariable {
void t1() {
if (true)
int x = 0;
}
}
......@@ -26,7 +26,7 @@
// key: compiler.misc.where.description.typevar
// key: compiler.misc.where.typevar
// key: compiler.err.cant.apply.symbol.1
// key: compiler.misc.infer.no.conforming.assignment.exists
// key: compiler.misc.inferred.do.not.conform.to.eq.bounds
// key: compiler.misc.captured.type
// options: -XDdiags=where,simpleNames
// run: simple
......
......@@ -26,7 +26,7 @@
// key: compiler.misc.where.description.typevar
// key: compiler.misc.where.typevar
// key: compiler.err.cant.apply.symbol.1
// key: compiler.misc.infer.no.conforming.assignment.exists
// key: compiler.misc.inferred.do.not.conform.to.eq.bounds
// key: compiler.misc.captured.type
// key: compiler.misc.type.null
// options: -XDdiags=where,simpleNames
......
/*
* Copyright (c) 2012, 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.misc.where.fresh.typevar
// key: compiler.misc.where.description.typevar.1
// key: compiler.misc.where.typevar
// key: compiler.misc.invalid.inferred.types
// key: compiler.err.prob.found.req.1
// key: compiler.misc.inferred.do.not.conform.to.upper.bounds
// options: -XDdiags=where,simpleNames
// run: simple
import java.util.*;
class WhereFreshTvar {
<T extends List<T>> T m() {}
{ List<String> ls = m(); }
}
Neg06.java:16:37: compiler.err.prob.found.req.1: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg06.CFoo), (compiler.misc.infer.no.conforming.instance.exists: X, Neg06.CFoo<X>, Neg06.CSuperFoo<java.lang.String>))
Neg06.java:16:37: compiler.err.prob.found.req.1: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: Neg06.CFoo), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number))
1 error
Neg07.java:17:27: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg07.Foo), (compiler.misc.inferred.do.not.conform.to.bounds: java.lang.String, java.lang.Number)
Neg07.java:17:27: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg07.Foo), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.String, java.lang.Number)
1 error
T6315770.java:16:42: compiler.err.prob.found.req.1: (compiler.misc.undetermined.type: <T>T6315770<T>, (compiler.misc.no.unique.maximal.instance.exists: T, java.lang.String,java.lang.Integer,java.lang.Runnable))
T6315770.java:17:40: compiler.err.prob.found.req.1: (compiler.misc.infer.no.conforming.instance.exists: T, T6315770<T>, T6315770<? super java.lang.String>)
T6315770.java:17:40: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer&java.lang.Runnable, java.lang.String))
2 errors
T6611449.java:18:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.inferred.do.not.conform.to.bounds: java.lang.Integer, S))}
T6611449.java:19:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.inferred.do.not.conform.to.bounds: java.lang.Integer, S)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.infer.arg.length.mismatch))}
T6611449.java:20:9: compiler.err.cant.apply.symbol.1: kindname.method, m1, T, int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.bounds: java.lang.Integer, S)
T6611449.java:21:9: compiler.err.cant.apply.symbol.1: kindname.method, m2, T,T, int,int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.bounds: java.lang.Integer, S)
T6611449.java:18:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.infer.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S))}
T6611449.java:19:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.infer.arg.length.mismatch))}
T6611449.java:20:9: compiler.err.cant.apply.symbol.1: kindname.method, m1, T, int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)
T6611449.java:21:9: compiler.err.cant.apply.symbol.1: kindname.method, m2, T,T, int,int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)
4 errors
T6638712b.java:14:21: compiler.err.prob.found.req.1: (compiler.misc.infer.no.conforming.instance.exists: T, T, java.lang.String)
T6638712b.java:14:21: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String,java.lang.Object))
1 error
T6638712d.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, U,java.util.List<java.util.List<U>>, int,java.util.List<java.util.List<java.lang.String>>, kindname.class, T6638712d, (compiler.misc.no.conforming.assignment.exists: int, java.lang.String)
T6638712d.java:16:9: compiler.err.cant.apply.symbol.1: kindname.method, m, U,java.util.List<java.util.List<U>>, int,java.util.List<java.util.List<java.lang.String>>, kindname.class, T6638712d, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.String, java.lang.Integer)
1 error
T6638712e.java:17:27: compiler.err.prob.found.req.1: (compiler.misc.infer.no.conforming.instance.exists: X, T6638712e.Foo<X,java.lang.String>, T6638712e.Foo<java.lang.Object,java.lang.String>)
T6638712e.java:17:27: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: X, (compiler.misc.no.conforming.assignment.exists: T6638712e.Foo<java.lang.Boolean,java.lang.Boolean>, T6638712e.Foo<? super java.lang.Object,? extends java.lang.Boolean>))
1 error
T6650759m.java:43:36: compiler.err.prob.found.req: java.util.List<? super java.lang.Integer>, java.util.List<? super java.lang.String>
T6650759m.java:43:36: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: Z, (compiler.misc.inferred.do.not.conform.to.lower.bounds: java.lang.Integer, java.lang.String))
1 error
T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))}
T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))}
T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))}
T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))}
T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String,java.lang.Object))}
T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Object))}
T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String,java.lang.Object))}
T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Object))}
4 errors
/**
* @test /nodynamiccopyright/
* @bug 7154127
* @summary Inference cleanup: remove bound check analysis from visitors in Types.java
* @compile/fail/ref=T7154127.out -XDrawDiagnostics T7154127.java
*/
class T7154127 {
static class B<V> {}
static class D extends B<E> {}
static class E extends B<D> {}
static class Triple<U,V,W> { }
static <T, Y extends B<U>, U extends B<Y>> Triple<T, Y, U> m() { return null; }
void test() {
Triple<B, ? extends D, ? extends E> t = m();
}
}
T7154127.java:19:49: compiler.err.prob.found.req.1: (compiler.misc.invalid.inferred.types: T,Y,U, (compiler.misc.inferred.do.not.conform.to.upper.bounds: Y, T7154127.D,T7154127.B<U>))
1 error
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -596,8 +596,8 @@ public class JavacParserTest extends TestCase {
public void testVariableInIfThen3() throws IOException {
String code = "package t; class Test { "+
"private static void t(String name) { " +
"if (name != null) abstract } }";
"private static void t() { " +
"if (true) abstract class F {} }}";
DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null,
......@@ -612,7 +612,51 @@ public class JavacParserTest extends TestCase {
}
assertEquals("testVariableInIfThen3",
Arrays.<String>asList("compiler.err.illegal.start.of.expr"),
Arrays.<String>asList("compiler.err.class.not.allowed"), codes);
}
public void testVariableInIfThen4() throws IOException {
String code = "package t; class Test { "+
"private static void t(String name) { " +
"if (name != null) interface X {} } }";
DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null,
null, Arrays.asList(new MyFileObject(code)));
ct.parse();
List<String> codes = new LinkedList<String>();
for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) {
codes.add(d.getCode());
}
assertEquals("testVariableInIfThen4",
Arrays.<String>asList("compiler.err.class.not.allowed"), codes);
}
public void testVariableInIfThen5() throws IOException {
String code = "package t; class Test { "+
"private static void t() { " +
"if (true) } }";
DiagnosticCollector<JavaFileObject> coll =
new DiagnosticCollector<JavaFileObject>();
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null,
null, Arrays.asList(new MyFileObject(code)));
ct.parse();
List<String> codes = new LinkedList<String>();
for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) {
codes.add(d.getCode());
}
assertEquals("testVariableInIfThen5",
Arrays.<String>asList("compiler.err.illegal.start.of.stmt"),
codes);
}
......@@ -808,8 +852,6 @@ public class JavacParserTest extends TestCase {
testPositionBrokenSource126732b();
// Fails, these tests yet to be addressed
testVariableInIfThen1();
testVariableInIfThen2();
testPositionForEnumModifiers();
testStartPositionEnumConstantInit();
}
......@@ -821,7 +863,11 @@ public class JavacParserTest extends TestCase {
testPreferredPositionForBinaryOp();
testStartPositionForMethodWithoutModifiers();
testVarPos();
testVariableInIfThen1();
testVariableInIfThen2();
testVariableInIfThen3();
testVariableInIfThen4();
testVariableInIfThen5();
testMissingExponent();
testTryResourcePos();
testOperatorMissingError();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册