mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-25 01:30:10 +00:00
Merge
This commit is contained in:
commit
47dafa22a0
@ -25,6 +25,7 @@
|
||||
|
||||
package com.sun.tools.javac.comp;
|
||||
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.code.*;
|
||||
import com.sun.tools.javac.code.Scope.WriteableScope;
|
||||
@ -95,6 +96,13 @@ public class AttrContext {
|
||||
*/
|
||||
Type defaultSuperCallSite = null;
|
||||
|
||||
/** Tree that when non null, is to be preferentially used in diagnostics.
|
||||
* Usually Env<AttrContext>.tree is the tree to be referred to in messages,
|
||||
* but this may not be true during the window a method is looked up in enclosing
|
||||
* contexts (JDK-8145466)
|
||||
*/
|
||||
JCTree preferredTreeForDiagnostics;
|
||||
|
||||
/** Duplicate this context, replacing scope field and copying all others.
|
||||
*/
|
||||
AttrContext dup(WriteableScope scope) {
|
||||
@ -112,6 +120,7 @@ public class AttrContext {
|
||||
info.isSpeculative = isSpeculative;
|
||||
info.isAnonymousDiamond = isAnonymousDiamond;
|
||||
info.isNewClass = isNewClass;
|
||||
info.preferredTreeForDiagnostics = preferredTreeForDiagnostics;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -722,7 +722,8 @@ public class Resolve {
|
||||
Warner warn) {
|
||||
//should we expand formals?
|
||||
boolean useVarargs = deferredAttrContext.phase.isVarargsRequired();
|
||||
List<JCExpression> trees = TreeInfo.args(env.tree);
|
||||
JCTree callTree = treeForDiagnostics(env);
|
||||
List<JCExpression> trees = TreeInfo.args(callTree);
|
||||
|
||||
//inference context used during this method check
|
||||
InferenceContext inferenceContext = deferredAttrContext.inferenceContext;
|
||||
@ -731,7 +732,7 @@ public class Resolve {
|
||||
|
||||
if (varargsFormal == null &&
|
||||
argtypes.size() != formals.size()) {
|
||||
reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
|
||||
reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
|
||||
}
|
||||
|
||||
while (argtypes.nonEmpty() && formals.head != varargsFormal) {
|
||||
@ -743,7 +744,7 @@ public class Resolve {
|
||||
}
|
||||
|
||||
if (formals.head != varargsFormal) {
|
||||
reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
|
||||
reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
|
||||
}
|
||||
|
||||
if (useVarargs) {
|
||||
@ -759,6 +760,11 @@ public class Resolve {
|
||||
}
|
||||
}
|
||||
|
||||
// where
|
||||
private JCTree treeForDiagnostics(Env<AttrContext> env) {
|
||||
return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual argument conforms to the corresponding formal?
|
||||
*/
|
||||
@ -1847,17 +1853,23 @@ public class Resolve {
|
||||
boolean staticOnly = false;
|
||||
while (env1.outer != null) {
|
||||
if (isStatic(env1)) staticOnly = true;
|
||||
Symbol sym = findMethod(
|
||||
env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
|
||||
allowBoxing, useVarargs);
|
||||
if (sym.exists()) {
|
||||
if (staticOnly &&
|
||||
sym.kind == MTH &&
|
||||
sym.owner.kind == TYP &&
|
||||
(sym.flags() & STATIC) == 0) return new StaticError(sym);
|
||||
else return sym;
|
||||
} else {
|
||||
bestSoFar = bestOf(bestSoFar, sym);
|
||||
Assert.check(env1.info.preferredTreeForDiagnostics == null);
|
||||
env1.info.preferredTreeForDiagnostics = env.tree;
|
||||
try {
|
||||
Symbol sym = findMethod(
|
||||
env1, env1.enclClass.sym.type, name, argtypes, typeargtypes,
|
||||
allowBoxing, useVarargs);
|
||||
if (sym.exists()) {
|
||||
if (staticOnly &&
|
||||
sym.kind == MTH &&
|
||||
sym.owner.kind == TYP &&
|
||||
(sym.flags() & STATIC) == 0) return new StaticError(sym);
|
||||
else return sym;
|
||||
} else {
|
||||
bestSoFar = bestOf(bestSoFar, sym);
|
||||
}
|
||||
} finally {
|
||||
env1.info.preferredTreeForDiagnostics = null;
|
||||
}
|
||||
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
|
||||
env1 = env1.outer;
|
||||
@ -4184,7 +4196,11 @@ public class Resolve {
|
||||
DiagnosticPosition preferedPos, DiagnosticSource preferredSource,
|
||||
DiagnosticType preferredKind, JCDiagnostic d) {
|
||||
JCDiagnostic cause = (JCDiagnostic)d.getArgs()[causeIndex];
|
||||
return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(),
|
||||
DiagnosticPosition pos = d.getDiagnosticPosition();
|
||||
if (pos == null) {
|
||||
pos = preferedPos;
|
||||
}
|
||||
return diags.create(preferredKind, preferredSource, pos,
|
||||
"prob.found.req", cause);
|
||||
}
|
||||
}
|
||||
|
||||
18
langtools/test/tools/javac/diags/DiagnosticRewriterTest.java
Normal file
18
langtools/test/tools/javac/diags/DiagnosticRewriterTest.java
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8145466
|
||||
* @summary javac: No line numbers in compilation error
|
||||
* @compile/fail/ref=DiagnosticRewriterTest.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest.java
|
||||
*/
|
||||
|
||||
class DiagnosticRewriterTest {
|
||||
void test() {
|
||||
new Object() {
|
||||
void g() {
|
||||
m(2L);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void m(int i) { }
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
DiagnosticRewriterTest.java:12:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int)
|
||||
- compiler.note.compressed.diags
|
||||
1 error
|
||||
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8145466
|
||||
* @summary javac: No line numbers in compilation error
|
||||
* @compile/fail/ref=DiagnosticRewriterTest2.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest2.java
|
||||
*/
|
||||
|
||||
class DiagnosticRewriterTest2 {
|
||||
class Bar {
|
||||
Bar(Object o) { }
|
||||
}
|
||||
void test() {
|
||||
new Bar(null) {
|
||||
void g() {
|
||||
m(2L);
|
||||
m();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void m(int i) { }
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
DiagnosticRewriterTest2.java:15:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int)
|
||||
DiagnosticRewriterTest2.java:16:13: compiler.err.cant.apply.symbol: kindname.method, m, int, compiler.misc.no.args, kindname.class, DiagnosticRewriterTest2, (compiler.misc.arg.length.mismatch)
|
||||
- compiler.note.compressed.diags
|
||||
2 errors
|
||||
@ -3,7 +3,7 @@
|
||||
* @bug 6380059
|
||||
* @summary Emit warnings for proprietary packages in the boot class path
|
||||
* @author Peter von der Ah\u00e9
|
||||
* @modules java.base/sun.misc
|
||||
* @modules java.base/sun.security.x509
|
||||
* @compile WarnVariable.java
|
||||
* @compile/fail/ref=WarnVariable.out -XDrawDiagnostics -Werror WarnVariable.java
|
||||
* @compile/fail/ref=WarnVariable.out -XDrawDiagnostics -Werror -nowarn WarnVariable.java
|
||||
@ -12,6 +12,6 @@
|
||||
|
||||
public class WarnVariable {
|
||||
public static void main(String... args) {
|
||||
System.out.println(sun.misc.FloatConsts.POSITIVE_INFINITY);
|
||||
System.out.println(sun.security.x509.X509CertImpl.NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
WarnVariable.java:15:36: compiler.warn.sun.proprietary: sun.misc.FloatConsts
|
||||
WarnVariable.java:15:45: compiler.warn.sun.proprietary: sun.security.x509.X509CertImpl
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
1 warning
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* @bug 6380059
|
||||
* @summary Emit warnings for proprietary packages in the boot class path
|
||||
* @author Peter von der Ah\u00e9
|
||||
* @modules java.base/sun.misc
|
||||
* @modules java.base/sun.security.x509
|
||||
* @compile WarnWildcard.java
|
||||
* @compile/fail/ref=WarnWildcard.out -XDrawDiagnostics -Werror WarnWildcard.java
|
||||
* @compile/fail/ref=WarnWildcard.out -XDrawDiagnostics -Werror -nowarn WarnWildcard.java
|
||||
@ -11,5 +11,5 @@
|
||||
*/
|
||||
|
||||
public class WarnWildcard {
|
||||
java.util.Collection<? extends sun.misc.FloatConsts> x;
|
||||
java.util.Collection<? extends sun.security.x509.X509CertImpl> x;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
WarnWildcard.java:14:44: compiler.warn.sun.proprietary: sun.misc.FloatConsts
|
||||
WarnWildcard.java:14:53: compiler.warn.sun.proprietary: sun.security.x509.X509CertImpl
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
1 warning
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user