|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -557,37 +557,24 @@ Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
|
557 | 557 | List<Type> argtypes) {
|
558 | 558 | final Type restype;
|
559 | 559 |
|
560 |
| - if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType)) { |
561 |
| - // The return type of the polymorphic signature is polymorphic, |
562 |
| - // and is computed from the enclosing tree E, as follows: |
563 |
| - // if E is a cast, then use the target type of the cast expression |
564 |
| - // as a return type; if E is an expression statement, the return |
565 |
| - // type is 'void'; otherwise |
566 |
| - // the return type is simply 'Object'. A correctness check ensures |
567 |
| - // that env.next refers to the lexically enclosing environment in |
568 |
| - // which the polymorphic signature call environment is nested. |
569 |
| - |
570 |
| - switch (env.next.tree.getTag()) { |
571 |
| - case TYPECAST: |
572 |
| - JCTypeCast castTree = (JCTypeCast)env.next.tree; |
573 |
| - restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? |
574 |
| - castTree.clazz.type : |
575 |
| - syms.objectType; |
576 |
| - break; |
577 |
| - case EXEC: |
578 |
| - JCTree.JCExpressionStatement execTree = |
579 |
| - (JCTree.JCExpressionStatement)env.next.tree; |
580 |
| - restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ? |
581 |
| - syms.voidType : |
582 |
| - syms.objectType; |
583 |
| - break; |
584 |
| - default: |
585 |
| - restype = syms.objectType; |
586 |
| - } |
587 |
| - } else { |
588 |
| - // The return type of the polymorphic signature is fixed |
589 |
| - // (not polymorphic) |
590 |
| - restype = spMethod.getReturnType(); |
| 560 | + Type spType = spMethod == null ? syms.objectType : spMethod.getReturnType(); |
| 561 | + |
| 562 | + switch (env.next.tree.getTag()) { |
| 563 | + case TYPECAST: |
| 564 | + JCTypeCast castTree = (JCTypeCast)env.next.tree; |
| 565 | + restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? |
| 566 | + castTree.clazz.type : |
| 567 | + spType; |
| 568 | + break; |
| 569 | + case EXEC: |
| 570 | + JCTree.JCExpressionStatement execTree = |
| 571 | + (JCTree.JCExpressionStatement)env.next.tree; |
| 572 | + restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ? |
| 573 | + syms.voidType : |
| 574 | + spType; |
| 575 | + break; |
| 576 | + default: |
| 577 | + restype = spType; |
591 | 578 | }
|
592 | 579 |
|
593 | 580 | List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
|
|
0 commit comments