@@ -1236,6 +1236,7 @@ Symbol findIdentInType(Env<AttrContext> env, Type site,
12361236 */
12371237 Symbol access (Symbol sym ,
12381238 DiagnosticPosition pos ,
1239+ Symbol location ,
12391240 Type site ,
12401241 Name name ,
12411242 boolean qualified ,
@@ -1246,25 +1247,48 @@ Symbol access(Symbol sym,
12461247 if (!site .isErroneous () &&
12471248 !Type .isErroneous (argtypes ) &&
12481249 (typeargtypes ==null || !Type .isErroneous (typeargtypes )))
1249- logResolveError (errSym , pos , site , name , argtypes , typeargtypes );
1250+ logResolveError (errSym , pos , location , site , name , argtypes , typeargtypes );
12501251 sym = errSym .access (name , qualified ? site .tsym : syms .noSymbol );
12511252 }
12521253 return sym ;
12531254 }
12541255
1255- /** Same as above , but without type arguments and arguments .
1256+ /** Same as original access() , but without location .
12561257 */
12571258 Symbol access (Symbol sym ,
12581259 DiagnosticPosition pos ,
12591260 Type site ,
12601261 Name name ,
1262+ boolean qualified ,
1263+ List <Type > argtypes ,
1264+ List <Type > typeargtypes ) {
1265+ return access (sym , pos , site .tsym , site , name , qualified , argtypes , typeargtypes );
1266+ }
1267+
1268+ /** Same as original access(), but without type arguments and arguments.
1269+ */
1270+ Symbol access (Symbol sym ,
1271+ DiagnosticPosition pos ,
1272+ Symbol location ,
1273+ Type site ,
1274+ Name name ,
12611275 boolean qualified ) {
12621276 if (sym .kind >= AMBIGUOUS )
1263- return access (sym , pos , site , name , qualified , List .<Type >nil (), null );
1277+ return access (sym , pos , location , site , name , qualified , List .<Type >nil (), null );
12641278 else
12651279 return sym ;
12661280 }
12671281
1282+ /** Same as original access(), but without location, type arguments and arguments.
1283+ */
1284+ Symbol access (Symbol sym ,
1285+ DiagnosticPosition pos ,
1286+ Type site ,
1287+ Name name ,
1288+ boolean qualified ) {
1289+ return access (sym , pos , site .tsym , site , name , qualified );
1290+ }
1291+
12681292 /** Check that sym is not an abstract method.
12691293 */
12701294 void checkNonAbstract (DiagnosticPosition pos , Symbol sym ) {
@@ -1380,6 +1404,11 @@ private Symbol startResolution() {
13801404 Symbol resolveQualifiedMethod (DiagnosticPosition pos , Env <AttrContext > env ,
13811405 Type site , Name name , List <Type > argtypes ,
13821406 List <Type > typeargtypes ) {
1407+ return resolveQualifiedMethod (pos , env , site .tsym , site , name , argtypes , typeargtypes );
1408+ }
1409+ Symbol resolveQualifiedMethod (DiagnosticPosition pos , Env <AttrContext > env ,
1410+ Symbol location , Type site , Name name , List <Type > argtypes ,
1411+ List <Type > typeargtypes ) {
13831412 Symbol sym = startResolution ();
13841413 List <MethodResolutionPhase > steps = methodResolutionSteps ;
13851414 while (steps .nonEmpty () &&
@@ -1404,7 +1433,7 @@ Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
14041433 MethodResolutionPhase errPhase =
14051434 firstErroneousResolutionPhase ();
14061435 sym = access (methodResolutionCache .get (errPhase ),
1407- pos , site , name , true , argtypes , typeargtypes );
1436+ pos , location , site , name , true , argtypes , typeargtypes );
14081437 env .info .varArgs = errPhase .isVarargsRequired ;
14091438 }
14101439 } else if (allowMethodHandles && sym .isPolymorphicSignatureGeneric ()) {
@@ -1471,7 +1500,7 @@ public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContex
14711500 List <Type > argtypes ,
14721501 List <Type > typeargtypes ) {
14731502 Symbol sym = resolveQualifiedMethod (
1474- pos , env , site , name , argtypes , typeargtypes );
1503+ pos , env , site . tsym , site , name , argtypes , typeargtypes );
14751504 if (sym .kind == MTH ) return (MethodSymbol )sym ;
14761505 else throw new FatalError (
14771506 diags .fragment ("fatal.err.cant.locate.meth" ,
@@ -1546,11 +1575,13 @@ Symbol resolveDiamond(DiagnosticPosition pos,
15461575 null ;
15471576 Symbol errSym = new ResolveError (WRONG_MTH , "diamond error" ) {
15481577 @ Override
1549- JCDiagnostic getDiagnostic (DiagnosticType dkind , DiagnosticPosition pos , Type site , Name name , List <Type > argtypes , List <Type > typeargtypes ) {
1578+ JCDiagnostic getDiagnostic (DiagnosticType dkind , DiagnosticPosition pos ,
1579+ Symbol location , Type site , Name name , List <Type > argtypes , List <Type > typeargtypes ) {
15501580 String key = details == null ?
15511581 "cant.apply.diamond" :
15521582 "cant.apply.diamond.1" ;
1553- return diags .create (dkind , log .currentSource (), pos , key , diags .fragment ("diamond" , site .tsym ), details );
1583+ return diags .create (dkind , log .currentSource (), pos , key ,
1584+ diags .fragment ("diamond" , site .tsym ), details );
15541585 }
15551586 };
15561587 MethodResolutionPhase errPhase = firstErroneousResolutionPhase ();
@@ -1729,17 +1760,18 @@ Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) {
17291760
17301761 public void logAccessError (Env <AttrContext > env , JCTree tree , Type type ) {
17311762 AccessError error = new AccessError (env , type .getEnclosingType (), type .tsym );
1732- logResolveError (error , tree .pos (), type .getEnclosingType (), null , null , null );
1763+ logResolveError (error , tree .pos (), type .getEnclosingType (). tsym , type . getEnclosingType () , null , null , null );
17331764 }
17341765 //where
17351766 private void logResolveError (ResolveError error ,
17361767 DiagnosticPosition pos ,
1768+ Symbol location ,
17371769 Type site ,
17381770 Name name ,
17391771 List <Type > argtypes ,
17401772 List <Type > typeargtypes ) {
17411773 JCDiagnostic d = error .getDiagnostic (JCDiagnostic .DiagnosticType .ERROR ,
1742- pos , site , name , argtypes , typeargtypes );
1774+ pos , location , site , name , argtypes , typeargtypes );
17431775 if (d != null ) {
17441776 d .setFlag (DiagnosticFlag .RESOLVE_ERROR );
17451777 log .report (d );
@@ -1809,6 +1841,7 @@ protected Symbol access(Name name, TypeSymbol location) {
18091841 */
18101842 abstract JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
18111843 DiagnosticPosition pos ,
1844+ Symbol location ,
18121845 Type site ,
18131846 Name name ,
18141847 List <Type > argtypes ,
@@ -1874,6 +1907,7 @@ class SymbolNotFoundError extends ResolveError {
18741907 @ Override
18751908 JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
18761909 DiagnosticPosition pos ,
1910+ Symbol location ,
18771911 Type site ,
18781912 Name name ,
18791913 List <Type > argtypes ,
@@ -1884,16 +1918,23 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
18841918 return null ;
18851919
18861920 if (isOperator (name )) {
1921+ boolean isUnaryOp = argtypes .size () == 1 ;
1922+ String key = argtypes .size () == 1 ?
1923+ "operator.cant.be.applied" :
1924+ "operator.cant.be.applied.1" ;
1925+ Type first = argtypes .head ;
1926+ Type second = !isUnaryOp ? argtypes .tail .head : null ;
18871927 return diags .create (dkind , log .currentSource (), pos ,
1888- "operator.cant.be.applied" , name , argtypes );
1928+ key , name , first , second );
18891929 }
18901930 boolean hasLocation = false ;
1891- if (!site . tsym .name .isEmpty ()) {
1892- if (site . tsym .kind == PCK && !site .tsym .exists ()) {
1931+ if (!location .name .isEmpty ()) {
1932+ if (location .kind == PCK && !site .tsym .exists ()) {
18931933 return diags .create (dkind , log .currentSource (), pos ,
1894- "doesnt.exist" , site . tsym );
1934+ "doesnt.exist" , location );
18951935 }
1896- hasLocation = true ;
1936+ hasLocation = !location .name .equals (names ._this ) &&
1937+ !location .name .equals (names ._super );
18971938 }
18981939 boolean isConstructor = kind == ABSENT_MTH &&
18991940 name == names .table .names .init ;
@@ -1904,7 +1945,7 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
19041945 return diags .create (dkind , log .currentSource (), pos ,
19051946 errKey , kindname , idname , //symbol kindname, name
19061947 typeargtypes , argtypes , //type parameters and arguments (if any)
1907- typeKindName ( site ), site ); //location kindname, type
1948+ getLocationDiag ( location ) ); //location kindname, type
19081949 }
19091950 else {
19101951 return diags .create (dkind , log .currentSource (), pos ,
@@ -1925,6 +1966,16 @@ private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLo
19251966 }
19261967 return key + suffix ;
19271968 }
1969+ private JCDiagnostic getLocationDiag (Symbol location ) {
1970+ boolean isVar = location .kind == VAR ;
1971+ String key = isVar ?
1972+ "location.1" :
1973+ "location" ;
1974+ return diags .fragment (key ,
1975+ kindName (location ),
1976+ location ,
1977+ isVar ? location .type : null );
1978+ }
19281979 }
19291980
19301981 /**
@@ -1965,6 +2016,7 @@ public String toString() {
19652016 @ Override
19662017 JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
19672018 DiagnosticPosition pos ,
2019+ Symbol location ,
19682020 Type site ,
19692021 Name name ,
19702022 List <Type > argtypes ,
@@ -2016,6 +2068,7 @@ class InapplicableSymbolsError extends ResolveError {
20162068 @ Override
20172069 JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
20182070 DiagnosticPosition pos ,
2071+ Symbol location ,
20192072 Type site ,
20202073 Name name ,
20212074 List <Type > argtypes ,
@@ -2031,7 +2084,7 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
20312084 return new JCDiagnostic .MultilineDiagnostic (err , candidateDetails (site ));
20322085 } else {
20332086 return new SymbolNotFoundError (ABSENT_MTH ).getDiagnostic (dkind , pos ,
2034- site , name , argtypes , typeargtypes );
2087+ location , site , name , argtypes , typeargtypes );
20352088 }
20362089 }
20372090
@@ -2131,6 +2184,7 @@ public boolean exists() {
21312184 @ Override
21322185 JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
21332186 DiagnosticPosition pos ,
2187+ Symbol location ,
21342188 Type site ,
21352189 Name name ,
21362190 List <Type > argtypes ,
@@ -2140,7 +2194,7 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
21402194
21412195 if (sym .name == names .init && sym .owner != site .tsym ) {
21422196 return new SymbolNotFoundError (ABSENT_MTH ).getDiagnostic (dkind ,
2143- pos , site , name , argtypes , typeargtypes );
2197+ pos , location , site , name , argtypes , typeargtypes );
21442198 }
21452199 else if ((sym .flags () & PUBLIC ) != 0
21462200 || (env != null && this .site != null
@@ -2175,6 +2229,7 @@ class StaticError extends InvalidSymbolError {
21752229 @ Override
21762230 JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
21772231 DiagnosticPosition pos ,
2232+ Symbol location ,
21782233 Type site ,
21792234 Name name ,
21802235 List <Type > argtypes ,
@@ -2205,6 +2260,7 @@ class AmbiguityError extends InvalidSymbolError {
22052260 @ Override
22062261 JCDiagnostic getDiagnostic (JCDiagnostic .DiagnosticType dkind ,
22072262 DiagnosticPosition pos ,
2263+ Symbol location ,
22082264 Type site ,
22092265 Name name ,
22102266 List <Type > argtypes ,
0 commit comments