langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
author mcimadamore
Fri, 09 Mar 2012 17:10:56 +0000
changeset 12087 31eeebc3ef49
parent 12080 23101f54df44
child 12334 29e1bfdcba4e
permissions -rw-r--r--
7151802: compiler update caused sqe test failed Summary: Fix regression caused by 7144506 Reviewed-by: jjg, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
    28
import com.sun.tools.javac.tree.JCTree;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
    29
import com.sun.tools.javac.tree.JCTree.JCTypeCast;
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
    30
import com.sun.tools.javac.tree.TreeInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.code.Type.*;
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
    35
import com.sun.tools.javac.code.Type.ForAll.ConstraintKind;
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    36
import com.sun.tools.javac.code.Symbol.*;
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
    37
import com.sun.tools.javac.comp.Resolve.InapplicableMethodException;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
    38
import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
    39
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import static com.sun.tools.javac.code.TypeTags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
/** Helper class for type parameter inference, used by the attribution phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    45
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    46
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
public class Infer {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    protected static final Context.Key<Infer> inferKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        new Context.Key<Infer>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /** A value for prototypes that admit any type, including polymorphic ones. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public static final Type anyPoly = new Type(NONE, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    Types types;
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
    59
    Check chk;
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    60
    Resolve rs;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
    61
    Log log;
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
    62
    JCDiagnostic.Factory diags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    public static Infer instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        Infer instance = context.get(inferKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
            instance = new Infer(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    protected Infer(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        context.put(inferKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        types = Types.instance(context);
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    75
        rs = Resolve.instance(context);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
    76
        log = Log.instance(context);
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
    77
        chk = Check.instance(context);
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
    78
        diags = JCDiagnostic.Factory.instance(context);
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
    79
        ambiguousNoInstanceException =
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
    80
            new NoInstanceException(true, diags);
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
    81
        unambiguousNoInstanceException =
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
    82
            new NoInstanceException(false, diags);
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    83
        invalidInstanceException =
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    84
            new InvalidInstanceException(diags);
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    85
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
    88
    public static class InferenceException extends InapplicableMethodException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    91
        InferenceException(JCDiagnostic.Factory diags) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
    92
            super(diags);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        }
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    94
    }
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    95
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    96
    public static class NoInstanceException extends InferenceException {
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    97
        private static final long serialVersionUID = 1;
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    98
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
    99
        boolean isAmbiguous; // exist several incomparable best instances?
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   100
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   101
        NoInstanceException(boolean isAmbiguous, JCDiagnostic.Factory diags) {
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   102
            super(diags);
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   103
            this.isAmbiguous = isAmbiguous;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    }
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   106
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   107
    public static class InvalidInstanceException extends InferenceException {
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   108
        private static final long serialVersionUID = 2;
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   109
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   110
        InvalidInstanceException(JCDiagnostic.Factory diags) {
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   111
            super(diags);
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   112
        }
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   113
    }
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   114
1040
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
   115
    private final NoInstanceException ambiguousNoInstanceException;
c0f5acfd9d15 6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents: 735
diff changeset
   116
    private final NoInstanceException unambiguousNoInstanceException;
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   117
    private final InvalidInstanceException invalidInstanceException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
/***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 * Auxiliary type values and classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 ***************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /** A mapping that turns type variables into undetermined type variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    Mapping fromTypeVarFun = new Mapping("fromTypeVarFun") {
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
            public Type apply(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                if (t.tag == TYPEVAR) return new UndetVar(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                else return t.map(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /** A mapping that returns its type argument with every UndetVar replaced
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     *  by its `inst' field. Throws a NoInstanceException
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     *  if this not possible because an `inst' field is null.
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   135
     *  Note: mutually referring undertvars will be left uninstantiated
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   136
     *  (that is, they will be replaced by the underlying type-variable).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   138
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    Mapping getInstFun = new Mapping("getInstFun") {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            public Type apply(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                switch (t.tag) {
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   142
                    case UNKNOWN:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                        throw ambiguousNoInstanceException
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   144
                            .setMessage("undetermined.type");
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   145
                    case UNDETVAR:
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   146
                        UndetVar that = (UndetVar) t;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   147
                        if (that.inst == null)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   148
                            throw ambiguousNoInstanceException
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   149
                                .setMessage("type.variable.has.undetermined.type",
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   150
                                            that.qtype);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   151
                        return isConstraintCyclic(that) ?
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   152
                            that.qtype :
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   153
                            apply(that.inst);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   154
                        default:
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   155
                            return t.map(this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            }
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   158
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   159
            private boolean isConstraintCyclic(UndetVar uv) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   160
                Types.UnaryVisitor<Boolean> constraintScanner =
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   161
                        new Types.UnaryVisitor<Boolean>() {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   162
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   163
                    List<Type> seen = List.nil();
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   164
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   165
                    Boolean visit(List<Type> ts) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   166
                        for (Type t : ts) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   167
                            if (visit(t)) return true;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   168
                        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   169
                        return false;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   170
                    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   171
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   172
                    public Boolean visitType(Type t, Void ignored) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   173
                        return false;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   174
                    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   175
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   176
                    @Override
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   177
                    public Boolean visitClassType(ClassType t, Void ignored) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   178
                        if (t.isCompound()) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   179
                            return visit(types.supertype(t)) ||
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   180
                                    visit(types.interfaces(t));
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   181
                        } else {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   182
                            return visit(t.getTypeArguments());
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   183
                        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   184
                    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   185
                    @Override
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   186
                    public Boolean visitWildcardType(WildcardType t, Void ignored) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   187
                        return visit(t.type);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   188
                    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   189
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   190
                    @Override
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   191
                    public Boolean visitUndetVar(UndetVar t, Void ignored) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   192
                        if (seen.contains(t)) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   193
                            return true;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   194
                        } else {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   195
                            seen = seen.prepend(t);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   196
                            return visit(t.inst);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   197
                        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   198
                    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   199
                };
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   200
                return constraintScanner.visit(uv);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   201
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
/***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
 * Mini/Maximization of UndetVars
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
 ***************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    /** Instantiate undetermined type variable to its minimal upper bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     *  Throw a NoInstanceException if this not possible.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    void maximizeInst(UndetVar that, Warner warn) throws NoInstanceException {
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   212
        List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        if (that.inst == null) {
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   214
            if (hibounds.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                that.inst = syms.objectType;
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   216
            else if (hibounds.tail.isEmpty())
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   217
                that.inst = hibounds.head;
1991
aafb4bf914ee 6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents: 1257
diff changeset
   218
            else
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   219
                that.inst = types.glb(hibounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        }
1991
aafb4bf914ee 6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents: 1257
diff changeset
   221
        if (that.inst == null ||
3139
01d76d311f8e 6835428: regression: return-type inference rejects valid code
mcimadamore
parents: 2212
diff changeset
   222
            that.inst.isErroneous())
1991
aafb4bf914ee 6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents: 1257
diff changeset
   223
            throw ambiguousNoInstanceException
aafb4bf914ee 6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents: 1257
diff changeset
   224
                .setMessage("no.unique.maximal.instance.exists",
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   225
                            that.qtype, hibounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        private boolean isSubClass(Type t, final List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            t = t.baseType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            if (t.tag == TYPEVAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
                List<Type> bounds = types.getBounds((TypeVar)t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                for (Type s : ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                    if (!types.isSameType(t, s.baseType())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                        for (Type bound : bounds) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                            if (!isSubClass(bound, List.of(s.baseType())))
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                for (Type s : ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                    if (!t.tsym.isSubClass(s.baseType().tsym, types))
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   249
    private Filter<Type> errorFilter = new Filter<Type>() {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   250
        @Override
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   251
        public boolean accepts(Type t) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   252
            return !t.isErroneous();
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   253
        }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   254
    };
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   255
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
   256
    /** Instantiate undetermined type variable to the lub of all its lower bounds.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     *  Throw a NoInstanceException if this not possible.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    void minimizeInst(UndetVar that, Warner warn) throws NoInstanceException {
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   260
        List<Type> lobounds = Type.filter(that.lobounds, errorFilter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        if (that.inst == null) {
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   262
            if (lobounds.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                that.inst = syms.botType;
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   264
            else if (lobounds.tail.isEmpty())
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   265
                that.inst = lobounds.head.isPrimitive() ? syms.errType : lobounds.head;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
            else {
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   267
                that.inst = types.lub(lobounds);
162
6620f2a8e265 6611449: Internal Error thrown during generic method/constructor invocation
mcimadamore
parents: 10
diff changeset
   268
            }
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
   269
            if (that.inst == null || that.inst.tag == ERROR)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                    throw ambiguousNoInstanceException
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
                        .setMessage("no.unique.minimal.instance.exists",
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   272
                                    that.qtype, lobounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
            // VGJ: sort of inlined maximizeInst() below.  Adding
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            // bounds can cause lobounds that are above hibounds.
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   275
            List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
10628
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   276
            Type hb = null;
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   277
            if (hibounds.isEmpty())
10628
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   278
                hb = syms.objectType;
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   279
            else if (hibounds.tail.isEmpty())
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   280
                hb = hibounds.head;
10628
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   281
            else
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   282
                hb = types.glb(hibounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            if (hb == null ||
10628
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   284
                hb.isErroneous())
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   285
                throw ambiguousNoInstanceException
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   286
                        .setMessage("incompatible.upper.bounds",
dca7012223bc 7086601: Error message bug: cause for method mismatch is 'null'
mcimadamore
parents: 9720
diff changeset
   287
                                    that.qtype, hibounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   291
    Type asUndetType(Type t, List<Type> undetvars) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   292
        return types.subst(t, inferenceVars(undetvars), undetvars);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   293
    }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   294
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   295
    List<Type> inferenceVars(List<Type> undetvars) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   296
        ListBuffer<Type> tvars = ListBuffer.lb();
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   297
        for (Type uv : undetvars) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   298
            tvars.append(((UndetVar)uv).qtype);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   299
        }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   300
        return tvars.toList();
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   301
    }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   302
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
/***************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
 * Exported Methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
 ***************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    /** Try to instantiate expression type `that' to given type `to'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     *  If a maximal instantiation exists which makes this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     *  a subtype of type `to', return the instantiated type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     *  If no instantiation exists, or if several incomparable
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     *  best instantiations exist throw a NoInstanceException.
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    public Type instantiateExpr(ForAll that,
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                                Type to,
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   315
                                Warner warn) throws InferenceException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        List<Type> undetvars = Type.map(that.tvars, fromTypeVarFun);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        for (List<Type> l = undetvars; l.nonEmpty(); l = l.tail) {
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   318
            UndetVar uv = (UndetVar) l.head;
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   319
            TypeVar tv = (TypeVar)uv.qtype;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            ListBuffer<Type> hibounds = new ListBuffer<Type>();
6154
c1b0c6641b92 6938454: Unable to determine generic type in program that compiles under Java 6
mcimadamore
parents: 5847
diff changeset
   321
            for (Type t : that.getConstraints(tv, ConstraintKind.EXTENDS)) {
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   322
                hibounds.append(types.subst(t, that.tvars, undetvars));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            }
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   324
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   325
            List<Type> inst = that.getConstraints(tv, ConstraintKind.EQUAL);
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   326
            if (inst.nonEmpty() && inst.head.tag != BOT) {
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   327
                uv.inst = inst.head;
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   328
            }
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   329
            uv.hibounds = hibounds.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        Type qtype1 = types.subst(that.qtype, that.tvars, undetvars);
7331
02ffc087c654 6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents: 6934
diff changeset
   332
        if (!types.isSubtype(qtype1,
02ffc087c654 6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents: 6934
diff changeset
   333
                qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            throw unambiguousNoInstanceException
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   335
                .setMessage("infer.no.conforming.instance.exists",
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                            that.tvars, that.qtype, to);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        for (List<Type> l = undetvars; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            maximizeInst((UndetVar) l.head, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        // System.out.println(" = " + qtype1.map(getInstFun));//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        // check bounds
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        List<Type> targs = Type.map(undetvars, getInstFun);
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   344
        if (Type.containsAny(targs, that.tvars)) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   345
            //replace uninferred type-vars
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   346
            targs = types.subst(targs,
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   347
                    that.tvars,
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   348
                    instantiateAsUninferredVars(undetvars, that.tvars));
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   349
        }
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   350
        return chk.checkType(warn.pos(), that.inst(targs, types), to);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    }
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   352
    //where
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   353
    private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   354
        Assert.check(undetvars.length() == tvars.length());
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   355
        ListBuffer<Type> new_targs = ListBuffer.lb();
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   356
        //step 1 - create synthetic captured vars
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   357
        for (Type t : undetvars) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   358
            UndetVar uv = (UndetVar)t;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   359
            Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   360
            new_targs = new_targs.append(newArg);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   361
        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   362
        //step 2 - replace synthetic vars in their bounds
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   363
        List<Type> formals = tvars;
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   364
        for (Type t : new_targs.toList()) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   365
            CapturedType ct = (CapturedType)t;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   366
            ct.bound = types.subst(ct.bound, tvars, new_targs.toList());
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   367
            WildcardType wt = new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass);
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   368
            wt.bound = (TypeVar)formals.head;
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   369
            ct.wildcard = wt;
11550
1d70546d4d78 7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents: 10950
diff changeset
   370
            formals = formals.tail;
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   371
        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   372
        return new_targs.toList();
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 6154
diff changeset
   373
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    /** Instantiate method type `mt' by finding instantiations of
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     *  `tvars' so that method can be applied to `argtypes'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     */
5489
e7af65bf7577 6730476: invalid "unchecked generic array" warning
mcimadamore
parents: 3778
diff changeset
   378
    public Type instantiateMethod(final Env<AttrContext> env,
e7af65bf7577 6730476: invalid "unchecked generic array" warning
mcimadamore
parents: 3778
diff changeset
   379
                                  List<Type> tvars,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                                  MethodType mt,
5846
6df0e6bcb388 6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents: 5520
diff changeset
   381
                                  final Symbol msym,
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   382
                                  final List<Type> argtypes,
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   383
                                  final boolean allowBoxing,
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   384
                                  final boolean useVarargs,
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   385
                                  final Warner warn) throws InferenceException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        List<Type> undetvars = Type.map(tvars, fromTypeVarFun);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   388
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   389
        final List<Type> capturedArgs =
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   390
                rs.checkRawArgumentsAcceptable(env, undetvars, argtypes, mt.getParameterTypes(),
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   391
                    allowBoxing, useVarargs, warn, new InferenceCheckHandler(undetvars));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        // minimize as yet undetermined type variables
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        for (Type t : undetvars)
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            minimizeInst((UndetVar) t, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        /** Type variables instantiated to bottom */
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        ListBuffer<Type> restvars = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   400
        /** Undet vars instantiated to bottom */
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   401
        final ListBuffer<Type> restundet = new ListBuffer<Type>();
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   402
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        /** Instantiated types or TypeVars if under-constrained */
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        ListBuffer<Type> insttypes = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        /** Instantiated types or UndetVars if under-constrained */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        ListBuffer<Type> undettypes = new ListBuffer<Type>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        for (Type t : undetvars) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            UndetVar uv = (UndetVar)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            if (uv.inst.tag == BOT) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                restvars.append(uv.qtype);
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   413
                restundet.append(uv);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
                insttypes.append(uv.qtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                undettypes.append(uv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
                uv.inst = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
                insttypes.append(uv.inst);
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
                undettypes.append(uv.inst);
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        checkWithinBounds(tvars, undettypes.toList(), warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   424
        mt = (MethodType)types.subst(mt, tvars, insttypes.toList());
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   425
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        if (!restvars.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            // if there are uninstantiated variables,
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
            // quantify result type with them
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   429
            final List<Type> inferredTypes = insttypes.toList();
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   430
            final List<Type> all_tvars = tvars; //this is the wrong tvars
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   431
            return new UninferredMethodType(env.tree.pos(), msym, mt, restvars.toList()) {
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   432
                @Override
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   433
                List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   434
                    for (Type t : restundet.toList()) {
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   435
                        UndetVar uv = (UndetVar)t;
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   436
                        if (uv.qtype == tv) {
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   437
                            switch (ck) {
6154
c1b0c6641b92 6938454: Unable to determine generic type in program that compiles under Java 6
mcimadamore
parents: 5847
diff changeset
   438
                                case EXTENDS: return uv.hibounds.appendList(types.subst(types.getBounds(tv), all_tvars, inferredTypes));
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   439
                                case SUPER: return uv.lobounds;
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   440
                                case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil();
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   441
                            }
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   442
                        }
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   443
                    }
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   444
                    return List.nil();
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   445
                }
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   446
                @Override
12080
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   447
                void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   448
                    Type owntype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   449
                                       restype,
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   450
                                       types.subst(getThrownTypes(), tvars, inferred),
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   451
                                       qtype.tsym);
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   452
                    // check that actuals conform to inferred formals
12087
31eeebc3ef49 7151802: compiler update caused sqe test failed
mcimadamore
parents: 12080
diff changeset
   453
                    warn.clear();
12080
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   454
                    checkArgumentsAcceptable(env, capturedArgs, owntype.getParameterTypes(), allowBoxing, useVarargs, warn);
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   455
                    // check that inferred bounds conform to their bounds
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   456
                    checkWithinBounds(all_tvars,
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   457
                           types.subst(inferredTypes, tvars, inferred), warn);
12087
31eeebc3ef49 7151802: compiler update caused sqe test failed
mcimadamore
parents: 12080
diff changeset
   458
                    qtype = chk.checkMethod(owntype, msym, env, TreeInfo.args(env.tree), capturedArgs, useVarargs, warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED));
12080
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   459
                }
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   460
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        }
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   462
        else {
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   463
            // check that actuals conform to inferred formals
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   464
            checkArgumentsAcceptable(env, capturedArgs, mt.getParameterTypes(), allowBoxing, useVarargs, warn);
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   465
            // return instantiated version of method type
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   466
            return mt;
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   467
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   471
        /** inference check handler **/
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   472
        class InferenceCheckHandler implements Resolve.MethodCheckHandler {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   473
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   474
            List<Type> undetvars;
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   475
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   476
            public InferenceCheckHandler(List<Type> undetvars) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   477
                this.undetvars = undetvars;
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   478
            }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   479
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   480
            public InapplicableMethodException arityMismatch() {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   481
                return unambiguousNoInstanceException.setMessage("infer.arg.length.mismatch");
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   482
            }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   483
            public InapplicableMethodException argumentMismatch(boolean varargs, Type found, Type expected) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   484
                String key = varargs ?
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   485
                    "infer.varargs.argument.mismatch" :
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   486
                    "infer.no.conforming.assignment.exists";
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   487
                return unambiguousNoInstanceException.setMessage(key,
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   488
                        inferenceVars(undetvars), found, expected);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   489
            }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   490
            public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) {
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   491
                return unambiguousNoInstanceException.setMessage("inaccessible.varargs.type",
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   492
                        expected, Kinds.kindName(location), location);
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   493
            }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   494
        }
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   495
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   496
        /**
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   497
         * A delegated type representing a partially uninferred method type.
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   498
         * The return type of a partially uninferred method type is a ForAll
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   499
         * type - when the return type is instantiated (see Infer.instantiateExpr)
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   500
         * the underlying method type is also updated.
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   501
         */
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   502
        abstract class UninferredMethodType extends DelegatedType {
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   503
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   504
            final List<Type> tvars;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   505
            final Symbol msym;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   506
            final DiagnosticPosition pos;
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   507
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   508
            public UninferredMethodType(DiagnosticPosition pos, Symbol msym, MethodType mtype, List<Type> tvars) {
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   509
                super(METHOD, new MethodType(mtype.argtypes, null, mtype.thrown, mtype.tsym));
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   510
                this.tvars = tvars;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   511
                this.msym = msym;
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   512
                this.pos = pos;
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   513
                asMethodType().restype = new UninferredReturnType(tvars, mtype.restype);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   514
            }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   515
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   516
            @Override
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   517
            public MethodType asMethodType() {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   518
                return qtype.asMethodType();
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   519
            }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   520
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   521
            @Override
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   522
            public Type map(Mapping f) {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   523
                return qtype.map(f);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   524
            }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   525
12080
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   526
            abstract void instantiateReturnType(Type restype, List<Type> inferred, Types types);
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   527
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   528
            abstract List<Type> getConstraints(TypeVar tv, ConstraintKind ck);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   529
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   530
            class UninferredReturnType extends ForAll {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   531
                public UninferredReturnType(List<Type> tvars, Type restype) {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   532
                    super(tvars, restype);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   533
                }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   534
                @Override
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   535
                public Type inst(List<Type> actuals, Types types) {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   536
                    Type newRestype = super.inst(actuals, types);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   537
                    instantiateReturnType(newRestype, actuals, types);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   538
                    if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   539
                        log.note(pos, "deferred.method.inst", msym, UninferredMethodType.this.qtype, newRestype);
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   540
                    }
12080
23101f54df44 7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents: 11707
diff changeset
   541
                    return UninferredMethodType.this.qtype.getReturnType();
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   542
                }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   543
                @Override
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   544
                public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   545
                    return UninferredMethodType.this.getConstraints(tv, ck);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   546
                }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   547
            }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   548
        }
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   549
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   550
        private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals,
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   551
                boolean allowBoxing, boolean useVarargs, Warner warn) {
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   552
            try {
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   553
                rs.checkRawArgumentsAcceptable(env, actuals, formals,
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   554
                       allowBoxing, useVarargs, warn);
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   555
            }
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   556
            catch (InapplicableMethodException ex) {
8229
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   557
                // inferred method is not applicable
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   558
                throw invalidInstanceException.setMessage(ex.getDiagnostic());
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   559
            }
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   560
        }
39266c1b1b0e 6313164: javac generates code that fails byte code verification for the varargs feature
mcimadamore
parents: 8048
diff changeset
   561
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   562
    /** Try to instantiate argument type `that' to given type `to'.
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   563
     *  If this fails, try to insantiate `that' to `to' where
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   564
     *  every occurrence of a type variable in `tvars' is replaced
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   565
     *  by an unknown type.
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   566
     */
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   567
    private Type instantiateArg(ForAll that,
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   568
                                Type to,
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   569
                                List<Type> tvars,
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   570
                                Warner warn) throws InferenceException {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   571
        List<Type> targs;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   572
        try {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   573
            return instantiateExpr(that, to, warn);
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   574
        } catch (NoInstanceException ex) {
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   575
            Type to1 = to;
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   576
            for (List<Type> l = tvars; l.nonEmpty(); l = l.tail)
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   577
                to1 = types.subst(to1, List.of(l.head), List.of(syms.unknownType));
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   578
            return instantiateExpr(that, to1, warn);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        }
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   580
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
    /** check that type parameters are within their bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
     */
6154
c1b0c6641b92 6938454: Unable to determine generic type in program that compiles under Java 6
mcimadamore
parents: 5847
diff changeset
   584
    void checkWithinBounds(List<Type> tvars,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
                                   List<Type> arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
                                   Warner warn)
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   587
        throws InvalidInstanceException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        for (List<Type> tvs = tvars, args = arguments;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
             tvs.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
             tvs = tvs.tail, args = args.tail) {
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   591
            if (args.head instanceof UndetVar ||
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8036
diff changeset
   592
                    tvars.head.getUpperBound().isErroneous()) continue;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
            List<Type> bounds = types.subst(types.getBounds((TypeVar)tvs.head), tvars, arguments);
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            if (!types.isSubtypeUnchecked(args.head, bounds, warn))
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   595
                throw invalidInstanceException
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                    .setMessage("inferred.do.not.conform.to.bounds",
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   597
                                args.head, bounds);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
    }
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   600
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   601
    /**
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   602
     * Compute a synthetic method type corresponding to the requested polymorphic
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   603
     * method signature. The target return type is computed from the immediately
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   604
     * enclosing scope surrounding the polymorphic-signature call.
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   605
     */
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   606
    Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   607
                                            Name name,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   608
                                            MethodSymbol spMethod,  // sig. poly. method or null if none
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   609
                                            List<Type> argtypes) {
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   610
        final Type restype;
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   611
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   612
        //The return type for a polymorphic signature call is computed from
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   613
        //the enclosing tree E, as follows: if E is a cast, then use the
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   614
        //target type of the cast expression as a return type; if E is an
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   615
        //expression statement, the return type is 'void' - otherwise the
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   616
        //return type is simply 'Object'. A correctness check ensures that
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   617
        //env.next refers to the lexically enclosing environment in which
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   618
        //the polymorphic signature call environment is nested.
6934
258e5f06880f 6991980: polymorphic signature calls don't share the same CP entries
mcimadamore
parents: 6710
diff changeset
   619
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   620
        switch (env.next.tree.getTag()) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
   621
            case TYPECAST:
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   622
                JCTypeCast castTree = (JCTypeCast)env.next.tree;
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   623
                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   624
                    castTree.clazz.type :
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   625
                    syms.objectType;
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   626
                break;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10816
diff changeset
   627
            case EXEC:
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   628
                JCTree.JCExpressionStatement execTree =
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   629
                        (JCTree.JCExpressionStatement)env.next.tree;
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   630
                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   631
                    syms.voidType :
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   632
                    syms.objectType;
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   633
                break;
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   634
            default:
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   635
                restype = syms.objectType;
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   636
        }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   637
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   638
        List<Type> paramtypes = Type.map(argtypes, implicitArgType);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   639
        List<Type> exType = spMethod != null ?
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   640
            spMethod.getThrownTypes() :
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   641
            List.of(syms.throwableType); // make it throw all exceptions
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   642
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   643
        MethodType mtype = new MethodType(paramtypes,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   644
                                          restype,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   645
                                          exType,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   646
                                          syms.methodClass);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   647
        return mtype;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   648
    }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   649
    //where
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   650
        Mapping implicitArgType = new Mapping ("implicitArgType") {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   651
                public Type apply(Type t) {
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   652
                    t = types.erasure(t);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   653
                    if (t.tag == BOT)
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   654
                        // nulls type as the marker type Null (which has no instances)
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   655
                        // infer as java.lang.Void for now
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   656
                        t = types.boxedClass(syms.voidType).type;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   657
                    return t;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   658
                }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   659
        };
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   660
    }