1552 // Attribute constructor arguments. |
1552 // Attribute constructor arguments. |
1553 List<Type> argtypes = attribArgs(tree.args, localEnv); |
1553 List<Type> argtypes = attribArgs(tree.args, localEnv); |
1554 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
1554 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
1555 |
1555 |
1556 if (TreeInfo.isDiamond(tree)) { |
1556 if (TreeInfo.isDiamond(tree)) { |
1557 clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes, true); |
1557 clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes); |
1558 clazz.type = clazztype; |
1558 clazz.type = clazztype; |
1559 } |
1559 } |
1560 |
1560 |
1561 // If we have made no mistakes in the class type... |
1561 // If we have made no mistakes in the class type... |
1562 if (clazztype.tag == CLASS) { |
1562 if (clazztype.tag == CLASS) { |
1690 Type attribDiamond(Env<AttrContext> env, |
1690 Type attribDiamond(Env<AttrContext> env, |
1691 JCNewClass tree, |
1691 JCNewClass tree, |
1692 Type clazztype, |
1692 Type clazztype, |
1693 Pair<Scope, Scope> mapping, |
1693 Pair<Scope, Scope> mapping, |
1694 List<Type> argtypes, |
1694 List<Type> argtypes, |
1695 List<Type> typeargtypes, |
1695 List<Type> typeargtypes) { |
1696 boolean reportErrors) { |
|
1697 if (clazztype.isErroneous() || mapping == erroneousMapping) { |
1696 if (clazztype.isErroneous() || mapping == erroneousMapping) { |
1698 //if the type of the instance creation expression is erroneous, |
1697 //if the type of the instance creation expression is erroneous, |
1699 //or something prevented us to form a valid mapping, return the |
1698 //or something prevented us to form a valid mapping, return the |
1700 //(possibly erroneous) type unchanged |
1699 //(possibly erroneous) type unchanged |
1701 return clazztype; |
1700 return clazztype; |
1729 try { |
1728 try { |
1730 constructor = rs.resolveDiamond(tree.pos(), |
1729 constructor = rs.resolveDiamond(tree.pos(), |
1731 env, |
1730 env, |
1732 clazztype.tsym.type, |
1731 clazztype.tsym.type, |
1733 argtypes, |
1732 argtypes, |
1734 typeargtypes, reportErrors); |
1733 typeargtypes); |
1735 } finally { |
1734 } finally { |
1736 ((ClassSymbol) clazztype.tsym).members_field = mapping.fst; |
1735 ((ClassSymbol) clazztype.tsym).members_field = mapping.fst; |
1737 } |
1736 } |
1738 if (constructor.kind == MTH) { |
1737 if (constructor.kind == MTH) { |
1739 ClassType ct = new ClassType(clazztype.getEnclosingType(), |
1738 ClassType ct = new ClassType(clazztype.getEnclosingType(), |
1758 clazztype = infer.instantiateExpr((ForAll) clazztype, |
1757 clazztype = infer.instantiateExpr((ForAll) clazztype, |
1759 pt.tag == NONE ? syms.objectType : pt, |
1758 pt.tag == NONE ? syms.objectType : pt, |
1760 Warner.noWarnings); |
1759 Warner.noWarnings); |
1761 } catch (Infer.InferenceException ex) { |
1760 } catch (Infer.InferenceException ex) { |
1762 //an error occurred while inferring uninstantiated type-variables |
1761 //an error occurred while inferring uninstantiated type-variables |
1763 //we need to optionally report an error |
1762 log.error(tree.clazz.pos(), |
1764 if (reportErrors) { |
1763 "cant.apply.diamond.1", |
1765 log.error(tree.clazz.pos(), |
1764 diags.fragment("diamond", clazztype.tsym), |
|
1765 ex.diagnostic); |
|
1766 } |
|
1767 } |
|
1768 clazztype = chk.checkClassType(tree.clazz.pos(), |
|
1769 clazztype, |
|
1770 true); |
|
1771 if (clazztype.tag == CLASS) { |
|
1772 List<Type> invalidDiamondArgs = chk.checkDiamond((ClassType)clazztype); |
|
1773 if (!clazztype.isErroneous() && invalidDiamondArgs.nonEmpty()) { |
|
1774 //one or more types inferred in the previous steps is either a |
|
1775 //captured type or an intersection type --- we need to report an error. |
|
1776 String subkey = invalidDiamondArgs.size() > 1 ? |
|
1777 "diamond.invalid.args" : |
|
1778 "diamond.invalid.arg"; |
|
1779 //The error message is of the kind: |
|
1780 // |
|
1781 //cannot infer type arguments for {clazztype}<>; |
|
1782 //reason: {subkey} |
|
1783 // |
|
1784 //where subkey is a fragment of the kind: |
|
1785 // |
|
1786 //type argument(s) {invalidDiamondArgs} inferred for {clazztype}<> is not allowed in this context |
|
1787 log.error(tree.clazz.pos(), |
1766 "cant.apply.diamond.1", |
1788 "cant.apply.diamond.1", |
1767 diags.fragment("diamond", clazztype.tsym), |
1789 diags.fragment("diamond", clazztype.tsym), |
1768 ex.diagnostic); |
1790 diags.fragment(subkey, |
1769 } |
1791 invalidDiamondArgs, |
1770 } |
1792 diags.fragment("diamond", clazztype.tsym))); |
1771 } |
|
1772 if (reportErrors) { |
|
1773 clazztype = chk.checkClassType(tree.clazz.pos(), |
|
1774 clazztype, |
|
1775 true); |
|
1776 if (clazztype.tag == CLASS) { |
|
1777 List<Type> invalidDiamondArgs = chk.checkDiamond((ClassType)clazztype); |
|
1778 if (!clazztype.isErroneous() && invalidDiamondArgs.nonEmpty()) { |
|
1779 //one or more types inferred in the previous steps is either a |
|
1780 //captured type or an intersection type --- we need to report an error. |
|
1781 String subkey = invalidDiamondArgs.size() > 1 ? |
|
1782 "diamond.invalid.args" : |
|
1783 "diamond.invalid.arg"; |
|
1784 //The error message is of the kind: |
|
1785 // |
|
1786 //cannot infer type arguments for {clazztype}<>; |
|
1787 //reason: {subkey} |
|
1788 // |
|
1789 //where subkey is a fragment of the kind: |
|
1790 // |
|
1791 //type argument(s) {invalidDiamondArgs} inferred for {clazztype}<> is not allowed in this context |
|
1792 log.error(tree.clazz.pos(), |
|
1793 "cant.apply.diamond.1", |
|
1794 diags.fragment("diamond", clazztype.tsym), |
|
1795 diags.fragment(subkey, |
|
1796 invalidDiamondArgs, |
|
1797 diags.fragment("diamond", clazztype.tsym))); |
|
1798 } |
|
1799 } |
1793 } |
1800 } |
1794 } |
1801 return clazztype; |
1795 return clazztype; |
1802 } |
1796 } |
1803 |
1797 |