1 /* |
1 /* |
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
483 } |
483 } |
484 |
484 |
485 @Override |
485 @Override |
486 public Type inst(List<Type> inferred, Types types) throws NoInstanceException { |
486 public Type inst(List<Type> inferred, Types types) throws NoInstanceException { |
487 List<Type> formals = types.subst(mt2.argtypes, tvars, inferred); |
487 List<Type> formals = types.subst(mt2.argtypes, tvars, inferred); |
488 if (!rs.argumentsAcceptable(capturedArgs, formals, |
488 // check that actuals conform to inferred formals |
489 allowBoxing, useVarargs, warn)) { |
489 checkArgumentsAcceptable(env, capturedArgs, formals, allowBoxing, useVarargs, warn); |
490 // inferred method is not applicable |
|
491 throw invalidInstanceException.setMessage("inferred.do.not.conform.to.params", formals, argtypes); |
|
492 } |
|
493 // check that inferred bounds conform to their bounds |
490 // check that inferred bounds conform to their bounds |
494 checkWithinBounds(all_tvars, |
491 checkWithinBounds(all_tvars, |
495 types.subst(inferredTypes, tvars, inferred), warn); |
492 types.subst(inferredTypes, tvars, inferred), warn); |
496 if (useVarargs) { |
493 if (useVarargs) { |
497 chk.checkVararg(env.tree.pos(), formals, msym); |
494 chk.checkVararg(env.tree.pos(), formals, msym); |
498 } |
495 } |
499 return super.inst(inferred, types); |
496 return super.inst(inferred, types); |
500 }}; |
497 }}; |
501 return mt2; |
498 return mt2; |
502 } |
499 } |
503 else if (!rs.argumentsAcceptable(capturedArgs, mt.getParameterTypes(), allowBoxing, useVarargs, warn)) { |
|
504 // inferred method is not applicable |
|
505 throw invalidInstanceException.setMessage("inferred.do.not.conform.to.params", mt.getParameterTypes(), argtypes); |
|
506 } |
|
507 else { |
500 else { |
|
501 // check that actuals conform to inferred formals |
|
502 checkArgumentsAcceptable(env, capturedArgs, mt.getParameterTypes(), allowBoxing, useVarargs, warn); |
508 // return instantiated version of method type |
503 // return instantiated version of method type |
509 return mt; |
504 return mt; |
510 } |
505 } |
511 } |
506 } |
512 //where |
507 //where |
|
508 |
|
509 private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals, |
|
510 boolean allowBoxing, boolean useVarargs, Warner warn) { |
|
511 try { |
|
512 rs.checkRawArgumentsAcceptable(env, actuals, formals, |
|
513 allowBoxing, useVarargs, warn); |
|
514 } |
|
515 catch (Resolve.InapplicableMethodException ex) { |
|
516 // inferred method is not applicable |
|
517 throw invalidInstanceException.setMessage(ex.getDiagnostic()); |
|
518 } |
|
519 } |
513 |
520 |
514 /** Try to instantiate argument type `that' to given type `to'. |
521 /** Try to instantiate argument type `that' to given type `to'. |
515 * If this fails, try to insantiate `that' to `to' where |
522 * If this fails, try to insantiate `that' to `to' where |
516 * every occurrence of a type variable in `tvars' is replaced |
523 * every occurrence of a type variable in `tvars' is replaced |
517 * by an unknown type. |
524 * by an unknown type. |