1581 * ResolveError classes, indicating error situations when accessing symbols |
1575 * ResolveError classes, indicating error situations when accessing symbols |
1582 ****************************************************************************/ |
1576 ****************************************************************************/ |
1583 |
1577 |
1584 public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) { |
1578 public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) { |
1585 AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym); |
1579 AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym); |
1586 error.report(log, tree.pos(), type.getEnclosingType(), null, null, null); |
1580 logResolveError(error, tree.pos(), type.getEnclosingType(), null, null, null); |
|
1581 } |
|
1582 //where |
|
1583 private void logResolveError(ResolveError error, |
|
1584 DiagnosticPosition pos, |
|
1585 Type site, |
|
1586 Name name, |
|
1587 List<Type> argtypes, |
|
1588 List<Type> typeargtypes) { |
|
1589 JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR, |
|
1590 pos, site, name, argtypes, typeargtypes); |
|
1591 if (d != null) |
|
1592 log.report(d); |
1587 } |
1593 } |
1588 |
1594 |
1589 private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args"); |
1595 private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args"); |
1590 |
1596 |
1591 public Object methodArguments(List<Type> argtypes) { |
1597 public Object methodArguments(List<Type> argtypes) { |
1592 return argtypes.isEmpty() ? noArgs : argtypes; |
1598 return argtypes.isEmpty() ? noArgs : argtypes; |
1593 } |
1599 } |
1594 |
1600 |
1595 /** Root class for resolve errors. |
1601 /** |
1596 * Instances of this class indicate "Symbol not found". |
1602 * Root class for resolution errors. Subclass of ResolveError |
1597 * Instances of subclass indicate other errors. |
1603 * represent a different kinds of resolution error - as such they must |
1598 */ |
1604 * specify how they map into concrete compiler diagnostics. |
1599 private class ResolveError extends Symbol { |
1605 */ |
1600 |
1606 private abstract class ResolveError extends Symbol { |
1601 ResolveError(int kind, Symbol sym, String debugName) { |
1607 |
|
1608 /** The name of the kind of error, for debugging only. */ |
|
1609 final String debugName; |
|
1610 |
|
1611 ResolveError(int kind, String debugName) { |
1602 super(kind, 0, null, null, null); |
1612 super(kind, 0, null, null, null); |
1603 this.debugName = debugName; |
1613 this.debugName = debugName; |
1604 this.sym = sym; |
1614 } |
1605 } |
1615 |
1606 |
1616 @Override |
1607 /** The name of the kind of error, for debugging only. |
|
1608 */ |
|
1609 final String debugName; |
|
1610 |
|
1611 /** The symbol that was determined by resolution, or errSymbol if none |
|
1612 * was found. |
|
1613 */ |
|
1614 final Symbol sym; |
|
1615 |
|
1616 /** The symbol that was a close mismatch, or null if none was found. |
|
1617 * wrongSym is currently set if a simgle method with the correct name, but |
|
1618 * the wrong parameters was found. |
|
1619 */ |
|
1620 Symbol wrongSym; |
|
1621 |
|
1622 /** An auxiliary explanation set in case of instantiation errors. |
|
1623 */ |
|
1624 JCDiagnostic explanation; |
|
1625 |
|
1626 |
|
1627 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1617 public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
1628 throw new AssertionError(); |
1618 throw new AssertionError(); |
1629 } |
1619 } |
1630 |
1620 |
1631 /** Print the (debug only) name of the kind of error. |
1621 @Override |
|
1622 public String toString() { |
|
1623 return debugName; |
|
1624 } |
|
1625 |
|
1626 @Override |
|
1627 public boolean exists() { |
|
1628 return false; |
|
1629 } |
|
1630 |
|
1631 /** |
|
1632 * Create an external representation for this erroneous symbol to be |
|
1633 * used during attribution - by default this returns the symbol of a |
|
1634 * brand new error type which stores the original type found |
|
1635 * during resolution. |
|
1636 * |
|
1637 * @param name the name used during resolution |
|
1638 * @param location the location from which the symbol is accessed |
1632 */ |
1639 */ |
1633 public String toString() { |
1640 protected Symbol access(Name name, TypeSymbol location) { |
1634 return debugName + " wrongSym=" + wrongSym + " explanation=" + explanation; |
1641 return types.createErrorType(name, location, syms.errSymbol.type).tsym; |
1635 } |
1642 } |
1636 |
1643 |
1637 /** Update wrongSym and explanation and return this. |
1644 /** |
|
1645 * Create a diagnostic representing this resolution error. |
|
1646 * |
|
1647 * @param dkind The kind of the diagnostic to be created (e.g error). |
|
1648 * @param pos The position to be used for error reporting. |
|
1649 * @param site The original type from where the selection took place. |
|
1650 * @param name The name of the symbol to be resolved. |
|
1651 * @param argtypes The invocation's value arguments, |
|
1652 * if we looked for a method. |
|
1653 * @param typeargtypes The invocation's type arguments, |
|
1654 * if we looked for a method. |
1638 */ |
1655 */ |
1639 ResolveError setWrongSym(Symbol sym, JCDiagnostic explanation) { |
1656 abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
1640 this.wrongSym = sym; |
1657 DiagnosticPosition pos, |
1641 this.explanation = explanation; |
1658 Type site, |
1642 return this; |
1659 Name name, |
1643 } |
1660 List<Type> argtypes, |
1644 |
1661 List<Type> typeargtypes); |
1645 /** Update wrongSym and return this. |
1662 |
1646 */ |
1663 /** |
1647 ResolveError setWrongSym(Symbol sym) { |
1664 * A name designates an operator if it consists |
1648 this.wrongSym = sym; |
1665 * of a non-empty sequence of operator symbols +-~!/*%&|^<>= |
1649 this.explanation = null; |
|
1650 return this; |
|
1651 } |
|
1652 |
|
1653 public boolean exists() { |
|
1654 switch (kind) { |
|
1655 case HIDDEN: |
|
1656 case ABSENT_VAR: |
|
1657 case ABSENT_MTH: |
|
1658 case ABSENT_TYP: |
|
1659 return false; |
|
1660 default: |
|
1661 return true; |
|
1662 } |
|
1663 } |
|
1664 |
|
1665 /** Report error. |
|
1666 * @param log The error log to be used for error reporting. |
|
1667 * @param pos The position to be used for error reporting. |
|
1668 * @param site The original type from where the selection took place. |
|
1669 * @param name The name of the symbol to be resolved. |
|
1670 * @param argtypes The invocation's value arguments, |
|
1671 * if we looked for a method. |
|
1672 * @param typeargtypes The invocation's type arguments, |
|
1673 * if we looked for a method. |
|
1674 */ |
|
1675 void report(Log log, DiagnosticPosition pos, Type site, Name name, |
|
1676 List<Type> argtypes, List<Type> typeargtypes) { |
|
1677 if (argtypes == null) |
|
1678 argtypes = List.nil(); |
|
1679 if (typeargtypes == null) |
|
1680 typeargtypes = List.nil(); |
|
1681 if (name != names.error) { |
|
1682 KindName kindname = absentKind(kind); |
|
1683 Name idname = name; |
|
1684 if (kind >= WRONG_MTHS && kind <= ABSENT_MTH) { |
|
1685 if (isOperator(name)) { |
|
1686 log.error(pos, "operator.cant.be.applied", |
|
1687 name, argtypes); |
|
1688 return; |
|
1689 } |
|
1690 if (name == names.init) { |
|
1691 kindname = KindName.CONSTRUCTOR; |
|
1692 idname = site.tsym.name; |
|
1693 } |
|
1694 } |
|
1695 if (kind == WRONG_MTH) { |
|
1696 Symbol ws = wrongSym.asMemberOf(site, types); |
|
1697 log.error(pos, |
|
1698 "cant.apply.symbol" + (explanation != null ? ".1" : ""), |
|
1699 kindname, |
|
1700 ws.name == names.init ? ws.owner.name : ws.name, |
|
1701 methodArguments(ws.type.getParameterTypes()), |
|
1702 methodArguments(argtypes), |
|
1703 kindName(ws.owner), |
|
1704 ws.owner.type, |
|
1705 explanation); |
|
1706 } else if (!site.tsym.name.isEmpty()) { |
|
1707 if (site.tsym.kind == PCK && !site.tsym.exists()) |
|
1708 log.error(pos, "doesnt.exist", site.tsym); |
|
1709 else { |
|
1710 String errKey = getErrorKey("cant.resolve.location", |
|
1711 argtypes, typeargtypes, |
|
1712 kindname); |
|
1713 log.error(pos, errKey, kindname, idname, //symbol kindname, name |
|
1714 typeargtypes, argtypes, //type parameters and arguments (if any) |
|
1715 typeKindName(site), site); //location kindname, type |
|
1716 } |
|
1717 } else { |
|
1718 String errKey = getErrorKey("cant.resolve", |
|
1719 argtypes, typeargtypes, |
|
1720 kindname); |
|
1721 log.error(pos, errKey, kindname, idname, //symbol kindname, name |
|
1722 typeargtypes, argtypes); //type parameters and arguments (if any) |
|
1723 } |
|
1724 } |
|
1725 } |
|
1726 //where |
|
1727 String getErrorKey(String key, List<Type> argtypes, List<Type> typeargtypes, KindName kindname) { |
|
1728 String suffix = ""; |
|
1729 switch (kindname) { |
|
1730 case METHOD: |
|
1731 case CONSTRUCTOR: { |
|
1732 suffix += ".args"; |
|
1733 suffix += typeargtypes.nonEmpty() ? ".params" : ""; |
|
1734 } |
|
1735 } |
|
1736 return key + suffix; |
|
1737 } |
|
1738 |
|
1739 /** A name designates an operator if it consists |
|
1740 * of a non-empty sequence of operator symbols +-~!/*%&|^<>= |
|
1741 */ |
1666 */ |
1742 boolean isOperator(Name name) { |
1667 boolean isOperator(Name name) { |
1743 int i = 0; |
1668 int i = 0; |
1744 while (i < name.getByteLength() && |
1669 while (i < name.getByteLength() && |
1745 "+-~!*/%&|^<>=".indexOf(name.getByteAt(i)) >= 0) i++; |
1670 "+-~!*/%&|^<>=".indexOf(name.getByteAt(i)) >= 0) i++; |
1746 return i > 0 && i == name.getByteLength(); |
1671 return i > 0 && i == name.getByteLength(); |
1747 } |
1672 } |
1748 } |
1673 } |
1749 |
1674 |
1750 /** Resolve error class indicating that a symbol is not accessible. |
1675 /** |
1751 */ |
1676 * This class is the root class of all resolution errors caused by |
1752 class AccessError extends ResolveError { |
1677 * an invalid symbol being found during resolution. |
|
1678 */ |
|
1679 abstract class InvalidSymbolError extends ResolveError { |
|
1680 |
|
1681 /** The invalid symbol found during resolution */ |
|
1682 Symbol sym; |
|
1683 |
|
1684 InvalidSymbolError(int kind, Symbol sym, String debugName) { |
|
1685 super(kind, debugName); |
|
1686 this.sym = sym; |
|
1687 } |
|
1688 |
|
1689 @Override |
|
1690 public boolean exists() { |
|
1691 return true; |
|
1692 } |
|
1693 |
|
1694 @Override |
|
1695 public String toString() { |
|
1696 return super.toString() + " wrongSym=" + sym; |
|
1697 } |
|
1698 |
|
1699 @Override |
|
1700 public Symbol access(Name name, TypeSymbol location) { |
|
1701 if (sym.kind >= AMBIGUOUS) |
|
1702 return ((ResolveError)sym).access(name, location); |
|
1703 else if ((sym.kind & ERRONEOUS) == 0 && (sym.kind & TYP) != 0) |
|
1704 return types.createErrorType(name, location, sym.type).tsym; |
|
1705 else |
|
1706 return sym; |
|
1707 } |
|
1708 } |
|
1709 |
|
1710 /** |
|
1711 * InvalidSymbolError error class indicating that a symbol matching a |
|
1712 * given name does not exists in a given site. |
|
1713 */ |
|
1714 class SymbolNotFoundError extends ResolveError { |
|
1715 |
|
1716 SymbolNotFoundError(int kind) { |
|
1717 super(kind, "symbol not found error"); |
|
1718 } |
|
1719 |
|
1720 @Override |
|
1721 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
|
1722 DiagnosticPosition pos, |
|
1723 Type site, |
|
1724 Name name, |
|
1725 List<Type> argtypes, |
|
1726 List<Type> typeargtypes) { |
|
1727 argtypes = argtypes == null ? List.<Type>nil() : argtypes; |
|
1728 typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes; |
|
1729 if (name == names.error) |
|
1730 return null; |
|
1731 |
|
1732 if (isOperator(name)) { |
|
1733 return diags.create(dkind, false, log.currentSource(), pos, |
|
1734 "operator.cant.be.applied", name, argtypes); |
|
1735 } |
|
1736 boolean hasLocation = false; |
|
1737 if (!site.tsym.name.isEmpty()) { |
|
1738 if (site.tsym.kind == PCK && !site.tsym.exists()) { |
|
1739 return diags.create(dkind, false, log.currentSource(), pos, |
|
1740 "doesnt.exist", site.tsym); |
|
1741 } |
|
1742 hasLocation = true; |
|
1743 } |
|
1744 boolean isConstructor = kind == ABSENT_MTH && |
|
1745 name == names.table.names.init; |
|
1746 KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind); |
|
1747 Name idname = isConstructor ? site.tsym.name : name; |
|
1748 String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation); |
|
1749 if (hasLocation) { |
|
1750 return diags.create(dkind, false, log.currentSource(), pos, |
|
1751 errKey, kindname, idname, //symbol kindname, name |
|
1752 typeargtypes, argtypes, //type parameters and arguments (if any) |
|
1753 typeKindName(site), site); //location kindname, type |
|
1754 } |
|
1755 else { |
|
1756 return diags.create(dkind, false, log.currentSource(), pos, |
|
1757 errKey, kindname, idname, //symbol kindname, name |
|
1758 typeargtypes, argtypes); //type parameters and arguments (if any) |
|
1759 } |
|
1760 } |
|
1761 //where |
|
1762 private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) { |
|
1763 String key = "cant.resolve"; |
|
1764 String suffix = hasLocation ? ".location" : ""; |
|
1765 switch (kindname) { |
|
1766 case METHOD: |
|
1767 case CONSTRUCTOR: { |
|
1768 suffix += ".args"; |
|
1769 suffix += hasTypeArgs ? ".params" : ""; |
|
1770 } |
|
1771 } |
|
1772 return key + suffix; |
|
1773 } |
|
1774 } |
|
1775 |
|
1776 /** |
|
1777 * InvalidSymbolError error class indicating that a given symbol |
|
1778 * (either a method, a constructor or an operand) is not applicable |
|
1779 * given an actual arguments/type argument list. |
|
1780 */ |
|
1781 class InapplicableSymbolError extends InvalidSymbolError { |
|
1782 |
|
1783 /** An auxiliary explanation set in case of instantiation errors. */ |
|
1784 JCDiagnostic explanation; |
|
1785 |
|
1786 InapplicableSymbolError(Symbol sym) { |
|
1787 super(WRONG_MTH, sym, "inapplicable symbol error"); |
|
1788 } |
|
1789 |
|
1790 /** Update sym and explanation and return this. |
|
1791 */ |
|
1792 InapplicableSymbolError setWrongSym(Symbol sym, JCDiagnostic explanation) { |
|
1793 this.sym = sym; |
|
1794 this.explanation = explanation; |
|
1795 return this; |
|
1796 } |
|
1797 |
|
1798 /** Update sym and return this. |
|
1799 */ |
|
1800 InapplicableSymbolError setWrongSym(Symbol sym) { |
|
1801 this.sym = sym; |
|
1802 this.explanation = null; |
|
1803 return this; |
|
1804 } |
|
1805 |
|
1806 @Override |
|
1807 public String toString() { |
|
1808 return super.toString() + " explanation=" + explanation; |
|
1809 } |
|
1810 |
|
1811 @Override |
|
1812 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
|
1813 DiagnosticPosition pos, |
|
1814 Type site, |
|
1815 Name name, |
|
1816 List<Type> argtypes, |
|
1817 List<Type> typeargtypes) { |
|
1818 if (name == names.error) |
|
1819 return null; |
|
1820 |
|
1821 if (isOperator(name)) { |
|
1822 return diags.create(dkind, false, log.currentSource(), |
|
1823 pos, "operator.cant.be.applied", name, argtypes); |
|
1824 } |
|
1825 else { |
|
1826 Symbol ws = sym.asMemberOf(site, types); |
|
1827 return diags.create(dkind, false, log.currentSource(), pos, |
|
1828 "cant.apply.symbol" + (explanation != null ? ".1" : ""), |
|
1829 kindName(ws), |
|
1830 ws.name == names.init ? ws.owner.name : ws.name, |
|
1831 methodArguments(ws.type.getParameterTypes()), |
|
1832 methodArguments(argtypes), |
|
1833 kindName(ws.owner), |
|
1834 ws.owner.type, |
|
1835 explanation); |
|
1836 } |
|
1837 } |
|
1838 |
|
1839 @Override |
|
1840 public Symbol access(Name name, TypeSymbol location) { |
|
1841 return types.createErrorType(name, location, syms.errSymbol.type).tsym; |
|
1842 } |
|
1843 } |
|
1844 |
|
1845 /** |
|
1846 * ResolveError error class indicating that a set of symbols |
|
1847 * (either methods, constructors or operands) is not applicable |
|
1848 * given an actual arguments/type argument list. |
|
1849 */ |
|
1850 class InapplicableSymbolsError extends ResolveError { |
|
1851 InapplicableSymbolsError(Symbol sym) { |
|
1852 super(WRONG_MTHS, "inapplicable symbols"); |
|
1853 } |
|
1854 |
|
1855 @Override |
|
1856 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
|
1857 DiagnosticPosition pos, |
|
1858 Type site, |
|
1859 Name name, |
|
1860 List<Type> argtypes, |
|
1861 List<Type> typeargtypes) { |
|
1862 return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos, |
|
1863 site, name, argtypes, typeargtypes); |
|
1864 } |
|
1865 } |
|
1866 |
|
1867 /** |
|
1868 * An InvalidSymbolError error class indicating that a symbol is not |
|
1869 * accessible from a given site |
|
1870 */ |
|
1871 class AccessError extends InvalidSymbolError { |
|
1872 |
|
1873 private Env<AttrContext> env; |
|
1874 private Type site; |
1753 |
1875 |
1754 AccessError(Symbol sym) { |
1876 AccessError(Symbol sym) { |
1755 this(null, null, sym); |
1877 this(null, null, sym); |
1756 } |
1878 } |
1757 |
1879 |
1761 this.site = site; |
1883 this.site = site; |
1762 if (debugResolve) |
1884 if (debugResolve) |
1763 log.error("proc.messager", sym + " @ " + site + " is inaccessible."); |
1885 log.error("proc.messager", sym + " @ " + site + " is inaccessible."); |
1764 } |
1886 } |
1765 |
1887 |
1766 private Env<AttrContext> env; |
1888 @Override |
1767 private Type site; |
1889 public boolean exists() { |
1768 |
1890 return false; |
1769 /** Report error. |
1891 } |
1770 * @param log The error log to be used for error reporting. |
1892 |
1771 * @param pos The position to be used for error reporting. |
1893 @Override |
1772 * @param site The original type from where the selection took place. |
1894 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
1773 * @param name The name of the symbol to be resolved. |
1895 DiagnosticPosition pos, |
1774 * @param argtypes The invocation's value arguments, |
1896 Type site, |
1775 * if we looked for a method. |
1897 Name name, |
1776 * @param typeargtypes The invocation's type arguments, |
1898 List<Type> argtypes, |
1777 * if we looked for a method. |
1899 List<Type> typeargtypes) { |
1778 */ |
1900 if (sym.owner.type.tag == ERROR) |
1779 void report(Log log, DiagnosticPosition pos, Type site, Name name, |
1901 return null; |
1780 List<Type> argtypes, List<Type> typeargtypes) { |
1902 |
1781 if (sym.owner.type.tag != ERROR) { |
1903 if (sym.name == names.init && sym.owner != site.tsym) { |
1782 if (sym.name == names.init && sym.owner != site.tsym) |
1904 return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, |
1783 new ResolveError(ABSENT_MTH, sym.owner, "absent method " + sym).report( |
1905 pos, site, name, argtypes, typeargtypes); |
1784 log, pos, site, name, argtypes, typeargtypes); |
1906 } |
1785 if ((sym.flags() & PUBLIC) != 0 |
1907 else if ((sym.flags() & PUBLIC) != 0 |
1786 || (env != null && this.site != null |
1908 || (env != null && this.site != null |
1787 && !isAccessible(env, this.site))) |
1909 && !isAccessible(env, this.site))) { |
1788 log.error(pos, "not.def.access.class.intf.cant.access", |
1910 return diags.create(dkind, false, log.currentSource(), |
1789 sym, sym.location()); |
1911 pos, "not.def.access.class.intf.cant.access", |
1790 else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) |
1912 sym, sym.location()); |
1791 log.error(pos, "report.access", sym, |
1913 } |
1792 asFlagSet(sym.flags() & (PRIVATE | PROTECTED)), |
1914 else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) { |
1793 sym.location()); |
1915 return diags.create(dkind, false, log.currentSource(), |
1794 else |
1916 pos, "report.access", sym, |
1795 log.error(pos, "not.def.public.cant.access", |
1917 asFlagSet(sym.flags() & (PRIVATE | PROTECTED)), |
1796 sym, sym.location()); |
1918 sym.location()); |
1797 } |
1919 } |
1798 } |
1920 else { |
1799 } |
1921 return diags.create(dkind, false, log.currentSource(), |
1800 |
1922 pos, "not.def.public.cant.access", sym, sym.location()); |
1801 /** Resolve error class indicating that an instance member was accessed |
1923 } |
1802 * from a static context. |
1924 } |
1803 */ |
1925 } |
1804 class StaticError extends ResolveError { |
1926 |
|
1927 /** |
|
1928 * InvalidSymbolError error class indicating that an instance member |
|
1929 * has erroneously been accessed from a static context. |
|
1930 */ |
|
1931 class StaticError extends InvalidSymbolError { |
|
1932 |
1805 StaticError(Symbol sym) { |
1933 StaticError(Symbol sym) { |
1806 super(STATICERR, sym, "static error"); |
1934 super(STATICERR, sym, "static error"); |
1807 } |
1935 } |
1808 |
1936 |
1809 /** Report error. |
1937 @Override |
1810 * @param log The error log to be used for error reporting. |
1938 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
1811 * @param pos The position to be used for error reporting. |
1939 DiagnosticPosition pos, |
1812 * @param site The original type from where the selection took place. |
1940 Type site, |
1813 * @param name The name of the symbol to be resolved. |
1941 Name name, |
1814 * @param argtypes The invocation's value arguments, |
1942 List<Type> argtypes, |
1815 * if we looked for a method. |
1943 List<Type> typeargtypes) { |
1816 * @param typeargtypes The invocation's type arguments, |
|
1817 * if we looked for a method. |
|
1818 */ |
|
1819 void report(Log log, |
|
1820 DiagnosticPosition pos, |
|
1821 Type site, |
|
1822 Name name, |
|
1823 List<Type> argtypes, |
|
1824 List<Type> typeargtypes) { |
|
1825 Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS) |
1944 Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS) |
1826 ? types.erasure(sym.type).tsym |
1945 ? types.erasure(sym.type).tsym |
1827 : sym); |
1946 : sym); |
1828 log.error(pos, "non-static.cant.be.ref", |
1947 return diags.create(dkind, false, log.currentSource(), pos, |
1829 kindName(sym), errSym); |
1948 "non-static.cant.be.ref", kindName(sym), errSym); |
1830 } |
1949 } |
1831 } |
1950 } |
1832 |
1951 |
1833 /** Resolve error class indicating an ambiguous reference. |
1952 /** |
1834 */ |
1953 * InvalidSymbolError error class indicating that a pair of symbols |
1835 class AmbiguityError extends ResolveError { |
1954 * (either methods, constructors or operands) are ambiguous |
1836 Symbol sym1; |
1955 * given an actual arguments/type argument list. |
|
1956 */ |
|
1957 class AmbiguityError extends InvalidSymbolError { |
|
1958 |
|
1959 /** The other maximally specific symbol */ |
1837 Symbol sym2; |
1960 Symbol sym2; |
1838 |
1961 |
1839 AmbiguityError(Symbol sym1, Symbol sym2) { |
1962 AmbiguityError(Symbol sym1, Symbol sym2) { |
1840 super(AMBIGUOUS, sym1, "ambiguity error"); |
1963 super(AMBIGUOUS, sym1, "ambiguity error"); |
1841 this.sym1 = sym1; |
|
1842 this.sym2 = sym2; |
1964 this.sym2 = sym2; |
1843 } |
1965 } |
1844 |
1966 |
1845 /** Report error. |
1967 @Override |
1846 * @param log The error log to be used for error reporting. |
1968 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, |
1847 * @param pos The position to be used for error reporting. |
1969 DiagnosticPosition pos, |
1848 * @param site The original type from where the selection took place. |
1970 Type site, |
1849 * @param name The name of the symbol to be resolved. |
1971 Name name, |
1850 * @param argtypes The invocation's value arguments, |
1972 List<Type> argtypes, |
1851 * if we looked for a method. |
1973 List<Type> typeargtypes) { |
1852 * @param typeargtypes The invocation's type arguments, |
|
1853 * if we looked for a method. |
|
1854 */ |
|
1855 void report(Log log, DiagnosticPosition pos, Type site, Name name, |
|
1856 List<Type> argtypes, List<Type> typeargtypes) { |
|
1857 AmbiguityError pair = this; |
1974 AmbiguityError pair = this; |
1858 while (true) { |
1975 while (true) { |
1859 if (pair.sym1.kind == AMBIGUOUS) |
1976 if (pair.sym.kind == AMBIGUOUS) |
1860 pair = (AmbiguityError)pair.sym1; |
1977 pair = (AmbiguityError)pair.sym; |
1861 else if (pair.sym2.kind == AMBIGUOUS) |
1978 else if (pair.sym2.kind == AMBIGUOUS) |
1862 pair = (AmbiguityError)pair.sym2; |
1979 pair = (AmbiguityError)pair.sym2; |
1863 else break; |
1980 else break; |
1864 } |
1981 } |
1865 Name sname = pair.sym1.name; |
1982 Name sname = pair.sym.name; |
1866 if (sname == names.init) sname = pair.sym1.owner.name; |
1983 if (sname == names.init) sname = pair.sym.owner.name; |
1867 log.error(pos, "ref.ambiguous", sname, |
1984 return diags.create(dkind, false, log.currentSource(), |
1868 kindName(pair.sym1), |
1985 pos, "ref.ambiguous", sname, |
1869 pair.sym1, |
1986 kindName(pair.sym), |
1870 pair.sym1.location(site, types), |
1987 pair.sym, |
|
1988 pair.sym.location(site, types), |
1871 kindName(pair.sym2), |
1989 kindName(pair.sym2), |
1872 pair.sym2, |
1990 pair.sym2, |
1873 pair.sym2.location(site, types)); |
1991 pair.sym2.location(site, types)); |
1874 } |
1992 } |
1875 } |
1993 } |