langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
author mcimadamore
Mon, 08 Apr 2013 15:51:41 +0100
changeset 16805 b419336382fd
parent 16566 604ce45d5f23
child 16975 124c8436d59c
permissions -rw-r--r--
8010922: Cleanup: add support for ad-hoc method check logic Summary: Support pluggable method checkers Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     1
/*
16805
b419336382fd 8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents: 16566
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     4
 *
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    10
 *
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    15
 * accompanied this code).
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    16
 *
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    20
 *
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    23
 * questions.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    24
 */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    25
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    26
package com.sun.tools.javac.comp;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    27
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    28
import com.sun.tools.javac.code.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    29
import com.sun.tools.javac.tree.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    30
import com.sun.tools.javac.util.*;
16805
b419336382fd 8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents: 16566
diff changeset
    31
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    32
import com.sun.tools.javac.code.Symbol.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    33
import com.sun.tools.javac.code.Type.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.javac.comp.Attr.ResultInfo;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    35
import com.sun.tools.javac.comp.Infer.InferenceContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    36
import com.sun.tools.javac.comp.Resolve.MethodResolutionPhase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.javac.tree.JCTree.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    38
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    39
import javax.tools.JavaFileObject;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    40
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    41
import java.util.ArrayList;
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
    42
import java.util.EnumSet;
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
    43
import java.util.LinkedHashSet;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    44
import java.util.Map;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    45
import java.util.Queue;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    46
import java.util.Set;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    47
import java.util.WeakHashMap;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    48
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
    49
import static com.sun.tools.javac.code.TypeTag.*;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    50
import static com.sun.tools.javac.tree.JCTree.Tag.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    51
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    52
/**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    53
 * This is an helper class that is used to perform deferred type-analysis.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    54
 * Each time a poly expression occurs in argument position, javac attributes it
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    55
 * with a temporary 'deferred type' that is checked (possibly multiple times)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    56
 * against an expected formal type.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    57
 *
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    58
 *  <p><b>This is NOT part of any supported API.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    59
 *  If you write code that depends on this, you do so at your own risk.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    60
 *  This code and its internal interfaces are subject to change or
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    61
 *  deletion without notice.</b>
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    62
 */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    63
public class DeferredAttr extends JCTree.Visitor {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    64
    protected static final Context.Key<DeferredAttr> deferredAttrKey =
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    65
        new Context.Key<DeferredAttr>();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    66
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    67
    final Attr attr;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    68
    final Check chk;
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
    69
    final JCDiagnostic.Factory diags;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    70
    final Enter enter;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    71
    final Infer infer;
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
    72
    final Resolve rs;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    73
    final Log log;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    74
    final Symtab syms;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    75
    final TreeMaker make;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    76
    final Types types;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    77
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    78
    public static DeferredAttr instance(Context context) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    79
        DeferredAttr instance = context.get(deferredAttrKey);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    80
        if (instance == null)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    81
            instance = new DeferredAttr(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    82
        return instance;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    83
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    84
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    85
    protected DeferredAttr(Context context) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    86
        context.put(deferredAttrKey, this);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    87
        attr = Attr.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    88
        chk = Check.instance(context);
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
    89
        diags = JCDiagnostic.Factory.instance(context);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    90
        enter = Enter.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    91
        infer = Infer.instance(context);
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
    92
        rs = Resolve.instance(context);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    93
        log = Log.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    94
        syms = Symtab.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    95
        make = TreeMaker.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    96
        types = Types.instance(context);
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
    97
        Names names = Names.instance(context);
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
    98
        stuckTree = make.Ident(names.empty).setType(Type.noType);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    99
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   100
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   101
    /** shared tree for stuck expressions */
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   102
    final JCTree stuckTree;
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   103
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   104
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   105
     * This type represents a deferred type. A deferred type starts off with
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   106
     * no information on the underlying expression type. Such info needs to be
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   107
     * discovered through type-checking the deferred type against a target-type.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   108
     * Every deferred type keeps a pointer to the AST node from which it originated.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   109
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   110
    public class DeferredType extends Type {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   111
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   112
        public JCExpression tree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   113
        Env<AttrContext> env;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   114
        AttrMode mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   115
        SpeculativeCache speculativeCache;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   116
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   117
        DeferredType(JCExpression tree, Env<AttrContext> env) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   118
            super(DEFERRED, null);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   119
            this.tree = tree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   120
            this.env = env.dup(tree, env.info.dup());
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   121
            this.speculativeCache = new SpeculativeCache();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   122
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   123
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   124
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   125
         * A speculative cache is used to keep track of all overload resolution rounds
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   126
         * that triggered speculative attribution on a given deferred type. Each entry
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   127
         * stores a pointer to the speculative tree and the resolution phase in which the entry
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   128
         * has been added.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   129
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   130
        class SpeculativeCache {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   131
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   132
            private Map<Symbol, List<Entry>> cache =
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   133
                    new WeakHashMap<Symbol, List<Entry>>();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   134
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   135
            class Entry {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   136
                JCTree speculativeTree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   137
                Resolve.MethodResolutionPhase phase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   138
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   139
                public Entry(JCTree speculativeTree, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   140
                    this.speculativeTree = speculativeTree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   141
                    this.phase = phase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   142
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   143
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   144
                boolean matches(Resolve.MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   145
                    return this.phase == phase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   146
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   147
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   148
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   149
            /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   150
             * Retrieve a speculative cache entry corresponding to given symbol
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   151
             * and resolution phase
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   152
             */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   153
            Entry get(Symbol msym, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   154
                List<Entry> entries = cache.get(msym);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   155
                if (entries == null) return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   156
                for (Entry e : entries) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   157
                    if (e.matches(phase)) return e;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   158
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   159
                return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   160
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   161
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   162
            /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   163
             * Stores a speculative cache entry corresponding to given symbol
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   164
             * and resolution phase
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   165
             */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   166
            void put(Symbol msym, JCTree speculativeTree, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   167
                List<Entry> entries = cache.get(msym);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   168
                if (entries == null) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   169
                    entries = List.nil();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   170
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   171
                cache.put(msym, entries.prepend(new Entry(speculativeTree, phase)));
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   172
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   173
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   174
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   175
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   176
         * Get the type that has been computed during a speculative attribution round
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   177
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   178
        Type speculativeType(Symbol msym, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   179
            SpeculativeCache.Entry e = speculativeCache.get(msym, phase);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   180
            return e != null ? e.speculativeTree.type : Type.noType;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   181
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   182
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   183
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   184
         * Check a deferred type against a potential target-type. Depending on
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   185
         * the current attribution mode, a normal vs. speculative attribution
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   186
         * round is performed on the underlying AST node. There can be only one
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   187
         * speculative round for a given target method symbol; moreover, a normal
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   188
         * attribution round must follow one or more speculative rounds.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   189
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   190
        Type check(ResultInfo resultInfo) {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   191
            return check(resultInfo, stuckVars(tree, env, resultInfo), basicCompleter);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   192
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   193
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   194
        Type check(ResultInfo resultInfo, List<Type> stuckVars, DeferredTypeCompleter deferredTypeCompleter) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   195
            DeferredAttrContext deferredAttrContext =
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   196
                    resultInfo.checkContext.deferredAttrContext();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   197
            Assert.check(deferredAttrContext != emptyDeferredAttrContext);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   198
            if (stuckVars.nonEmpty()) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   199
                deferredAttrContext.addDeferredAttrNode(this, resultInfo, stuckVars);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   200
                return Type.noType;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   201
            } else {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   202
                try {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   203
                    return deferredTypeCompleter.complete(this, resultInfo, deferredAttrContext);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   204
                } finally {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   205
                    mode = deferredAttrContext.mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   206
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   207
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   208
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   209
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   210
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   211
    /**
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   212
     * A completer for deferred types. Defines an entry point for type-checking
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   213
     * a deferred type.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   214
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   215
    interface DeferredTypeCompleter {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   216
        /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   217
         * Entry point for type-checking a deferred type. Depending on the
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   218
         * circumstances, type-checking could amount to full attribution
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   219
         * or partial structural check (aka potential applicability).
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   220
         */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   221
        Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   222
    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   223
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   224
    /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   225
     * A basic completer for deferred types. This completer type-checks a deferred type
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   226
     * using attribution; depending on the attribution mode, this could be either standard
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   227
     * or speculative attribution.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   228
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   229
    DeferredTypeCompleter basicCompleter = new DeferredTypeCompleter() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   230
        public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   231
            switch (deferredAttrContext.mode) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   232
                case SPECULATIVE:
16566
604ce45d5f23 8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents: 16326
diff changeset
   233
                    //Note: if a symbol is imported twice we might do two identical
604ce45d5f23 8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents: 16326
diff changeset
   234
                    //speculative rounds...
604ce45d5f23 8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents: 16326
diff changeset
   235
                    Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE);
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   236
                    JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   237
                    dt.speculativeCache.put(deferredAttrContext.msym, speculativeTree, deferredAttrContext.phase);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   238
                    return speculativeTree.type;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   239
                case CHECK:
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   240
                    Assert.check(dt.mode != null);
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   241
                    return attr.attribTree(dt.tree, dt.env, resultInfo);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   242
            }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   243
            Assert.error();
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   244
            return null;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   245
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   246
    };
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   247
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   248
    DeferredTypeCompleter dummyCompleter = new DeferredTypeCompleter() {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   249
        public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   250
            Assert.check(deferredAttrContext.mode == AttrMode.CHECK);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   251
            return dt.tree.type = Type.noType;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   252
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   253
    };
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   254
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   255
    /**
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   256
     * The 'mode' in which the deferred type is to be type-checked
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   257
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   258
    public enum AttrMode {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   259
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   260
         * A speculative type-checking round is used during overload resolution
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   261
         * mainly to generate constraints on inference variables. Side-effects
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   262
         * arising from type-checking the expression associated with the deferred
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   263
         * type are reversed after the speculative round finishes. This means the
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   264
         * expression tree will be left in a blank state.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   265
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   266
        SPECULATIVE,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   267
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   268
         * This is the plain type-checking mode. Produces side-effects on the underlying AST node
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   269
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   270
        CHECK;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   271
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   272
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   273
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   274
     * Routine that performs speculative type-checking; the input AST node is
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   275
     * cloned (to avoid side-effects cause by Attr) and compiler state is
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   276
     * restored after type-checking. All diagnostics (but critical ones) are
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   277
     * disabled during speculative type-checking.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   278
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   279
    JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
16309
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   280
        final JCTree newTree = new TreeCopier<Object>(make).copy(tree);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   281
        Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared()));
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   282
        speculativeEnv.info.scope.owner = env.info.scope.owner;
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14359
diff changeset
   283
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14359
diff changeset
   284
                new Log.DeferredDiagnosticHandler(log, new Filter<JCDiagnostic>() {
16309
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   285
            public boolean accepts(final JCDiagnostic d) {
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   286
                class PosScanner extends TreeScanner {
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   287
                    boolean found = false;
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   288
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   289
                    @Override
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   290
                    public void scan(JCTree tree) {
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   291
                        if (tree != null &&
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   292
                                tree.pos() == d.getDiagnosticPosition()) {
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   293
                            found = true;
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   294
                        }
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   295
                        super.scan(tree);
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   296
                    }
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   297
                };
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   298
                PosScanner posScanner = new PosScanner();
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   299
                posScanner.scan(newTree);
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   300
                return posScanner.found;
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14359
diff changeset
   301
            }
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14359
diff changeset
   302
        });
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   303
        try {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   304
            attr.attribTree(newTree, speculativeEnv, resultInfo);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   305
            unenterScanner.scan(newTree);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   306
            return newTree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   307
        } finally {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   308
            unenterScanner.scan(newTree);
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14359
diff changeset
   309
            log.popDiagnosticHandler(deferredDiagnosticHandler);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   310
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   311
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   312
    //where
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   313
        protected TreeScanner unenterScanner = new TreeScanner() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   314
            @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   315
            public void visitClassDef(JCClassDecl tree) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   316
                ClassSymbol csym = tree.sym;
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   317
                //if something went wrong during method applicability check
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   318
                //it is possible that nested expressions inside argument expression
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   319
                //are left unchecked - in such cases there's nothing to clean up.
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   320
                if (csym == null) return;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   321
                enter.typeEnvs.remove(csym);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   322
                chk.compiled.remove(csym.flatname);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   323
                syms.classes.remove(csym.flatname);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   324
                super.visitClassDef(tree);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   325
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   326
        };
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   327
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   328
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   329
     * A deferred context is created on each method check. A deferred context is
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   330
     * used to keep track of information associated with the method check, such as
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   331
     * the symbol of the method being checked, the overload resolution phase,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   332
     * the kind of attribution mode to be applied to deferred types and so forth.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   333
     * As deferred types are processed (by the method check routine) stuck AST nodes
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   334
     * are added (as new deferred attribution nodes) to this context. The complete()
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   335
     * routine makes sure that all pending nodes are properly processed, by
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   336
     * progressively instantiating all inference variables on which one or more
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   337
     * deferred attribution node is stuck.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   338
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   339
    class DeferredAttrContext {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   340
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   341
        /** attribution mode */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   342
        final AttrMode mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   343
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   344
        /** symbol of the method being checked */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   345
        final Symbol msym;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   346
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   347
        /** method resolution step */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   348
        final Resolve.MethodResolutionPhase phase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   349
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   350
        /** inference context */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   351
        final InferenceContext inferenceContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   352
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   353
        /** parent deferred context */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   354
        final DeferredAttrContext parent;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   355
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   356
        /** Warner object to report warnings */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   357
        final Warner warn;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   358
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   359
        /** list of deferred attribution nodes to be processed */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   360
        ArrayList<DeferredAttrNode> deferredAttrNodes = new ArrayList<DeferredAttrNode>();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   361
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   362
        DeferredAttrContext(AttrMode mode, Symbol msym, MethodResolutionPhase phase,
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   363
                InferenceContext inferenceContext, DeferredAttrContext parent, Warner warn) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   364
            this.mode = mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   365
            this.msym = msym;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   366
            this.phase = phase;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   367
            this.parent = parent;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   368
            this.warn = warn;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   369
            this.inferenceContext = inferenceContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   370
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   371
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   372
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   373
         * Adds a node to the list of deferred attribution nodes - used by Resolve.rawCheckArgumentsApplicable
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   374
         * Nodes added this way act as 'roots' for the out-of-order method checking process.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   375
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   376
        void addDeferredAttrNode(final DeferredType dt, ResultInfo resultInfo, List<Type> stuckVars) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   377
            deferredAttrNodes.add(new DeferredAttrNode(dt, resultInfo, stuckVars));
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   378
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   379
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   380
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   381
         * Incrementally process all nodes, by skipping 'stuck' nodes and attributing
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   382
         * 'unstuck' ones. If at any point no progress can be made (no 'unstuck' nodes)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   383
         * some inference variable might get eagerly instantiated so that all nodes
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   384
         * can be type-checked.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   385
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   386
        void complete() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   387
            while (!deferredAttrNodes.isEmpty()) {
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   388
                Set<Type> stuckVars = new LinkedHashSet<Type>();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   389
                boolean progress = false;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   390
                //scan a defensive copy of the node list - this is because a deferred
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   391
                //attribution round can add new nodes to the list
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   392
                for (DeferredAttrNode deferredAttrNode : List.from(deferredAttrNodes)) {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   393
                    if (!deferredAttrNode.process(this)) {
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   394
                        stuckVars.addAll(deferredAttrNode.stuckVars);
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   395
                    } else {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   396
                        deferredAttrNodes.remove(deferredAttrNode);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   397
                        progress = true;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   398
                    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   399
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   400
                if (!progress) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   401
                    //remove all variables that have already been instantiated
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   402
                    //from the list of stuck variables
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   403
                    inferenceContext.solveAny(List.from(stuckVars), warn);
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15374
diff changeset
   404
                    inferenceContext.notifyChange();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   405
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   406
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   407
        }
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   408
    }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   409
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   410
    /**
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   411
     * Class representing a deferred attribution node. It keeps track of
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   412
     * a deferred type, along with the expected target type information.
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   413
     */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   414
    class DeferredAttrNode implements Infer.FreeTypeListener {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   415
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   416
        /** underlying deferred type */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   417
        DeferredType dt;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   418
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   419
        /** underlying target type information */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   420
        ResultInfo resultInfo;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   421
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   422
        /** list of uninferred inference variables causing this node to be stuck */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   423
        List<Type> stuckVars;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   424
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   425
        DeferredAttrNode(DeferredType dt, ResultInfo resultInfo, List<Type> stuckVars) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   426
            this.dt = dt;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   427
            this.resultInfo = resultInfo;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   428
            this.stuckVars = stuckVars;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   429
            if (!stuckVars.isEmpty()) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   430
                resultInfo.checkContext.inferenceContext().addFreeTypeListener(stuckVars, this);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   431
            }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   432
        }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   433
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   434
        @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   435
        public void typesInferred(InferenceContext inferenceContext) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   436
            stuckVars = List.nil();
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   437
            resultInfo = resultInfo.dup(inferenceContext.asInstType(resultInfo.pt));
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   438
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   439
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   440
        /**
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   441
         * Process a deferred attribution node.
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   442
         * Invariant: a stuck node cannot be processed.
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   443
         */
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   444
        @SuppressWarnings("fallthrough")
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   445
        boolean process(DeferredAttrContext deferredAttrContext) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   446
            switch (deferredAttrContext.mode) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   447
                case SPECULATIVE:
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   448
                    dt.check(resultInfo, List.<Type>nil(), new StructuralStuckChecker());
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   449
                    return true;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   450
                case CHECK:
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   451
                    if (stuckVars.nonEmpty()) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   452
                        //stuck expression - see if we can propagate
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   453
                        if (deferredAttrContext.parent != emptyDeferredAttrContext &&
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   454
                                Type.containsAny(deferredAttrContext.parent.inferenceContext.inferencevars, List.from(stuckVars))) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   455
                            deferredAttrContext.parent.deferredAttrNodes.add(this);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   456
                            dt.check(resultInfo, List.<Type>nil(), dummyCompleter);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   457
                            return true;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   458
                        } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   459
                            return false;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   460
                        }
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   461
                    } else {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   462
                        dt.check(resultInfo, stuckVars, basicCompleter);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   463
                        return true;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   464
                    }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   465
                default:
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   466
                    throw new AssertionError("Bad mode");
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   467
            }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   468
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   469
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   470
        /**
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   471
         * Structural checker for stuck expressions
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   472
         */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   473
        class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   474
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   475
            ResultInfo resultInfo;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   476
            InferenceContext inferenceContext;
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   477
            Env<AttrContext> env;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   478
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   479
            public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   480
                this.resultInfo = resultInfo;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   481
                this.inferenceContext = deferredAttrContext.inferenceContext;
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   482
                this.env = dt.env.dup(dt.tree, dt.env.info.dup());
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   483
                dt.tree.accept(this);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   484
                dt.speculativeCache.put(deferredAttrContext.msym, stuckTree, deferredAttrContext.phase);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   485
                return Type.noType;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   486
            }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   487
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   488
            @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   489
            public void visitLambda(JCLambda tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   490
                Check.CheckContext checkContext = resultInfo.checkContext;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   491
                Type pt = resultInfo.pt;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   492
                if (inferenceContext.inferencevars.contains(pt)) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   493
                    //ok
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   494
                    return;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   495
                } else {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   496
                    //must be a functional descriptor
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   497
                    try {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   498
                        Type desc = types.findDescriptorType(pt);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   499
                        if (desc.getParameterTypes().length() != tree.params.length()) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   500
                            checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda"));
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   501
                        }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   502
                    } catch (Types.FunctionDescriptorLookupError ex) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   503
                        checkContext.report(null, ex.getDiagnostic());
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   504
                    }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   505
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   506
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   507
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   508
            @Override
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   509
            public void visitNewClass(JCNewClass tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   510
                //do nothing
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   511
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   512
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   513
            @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   514
            public void visitApply(JCMethodInvocation tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   515
                //do nothing
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   516
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   517
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   518
            @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   519
            public void visitReference(JCMemberReference tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   520
                Check.CheckContext checkContext = resultInfo.checkContext;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   521
                Type pt = resultInfo.pt;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   522
                if (inferenceContext.inferencevars.contains(pt)) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   523
                    //ok
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   524
                    return;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   525
                } else {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   526
                    try {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   527
                        types.findDescriptorType(pt);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   528
                    } catch (Types.FunctionDescriptorLookupError ex) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   529
                        checkContext.report(null, ex.getDiagnostic());
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   530
                    }
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   531
                    JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), env,
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   532
                            attr.memberReferenceQualifierResult(tree));
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   533
                    ListBuffer<Type> argtypes = ListBuffer.lb();
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   534
                    for (Type t : types.findDescriptorType(pt).getParameterTypes()) {
16805
b419336382fd 8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents: 16566
diff changeset
   535
                        argtypes.append(Type.noType);
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   536
                    }
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   537
                    JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree);
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   538
                    mref2.expr = exprTree;
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   539
                    Pair<Symbol, ?> lookupRes =
16805
b419336382fd 8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents: 16566
diff changeset
   540
                            rs.resolveMemberReference(tree, env, mref2, exprTree.type,
b419336382fd 8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents: 16566
diff changeset
   541
                                tree.name, argtypes.toList(), null, true, rs.arityMethodCheck);
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   542
                    switch (lookupRes.fst.kind) {
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   543
                        //note: as argtypes are erroneous types, type-errors must
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   544
                        //have been caused by arity mismatch
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   545
                        case Kinds.ABSENT_MTH:
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   546
                        case Kinds.WRONG_MTH:
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   547
                        case Kinds.WRONG_MTHS:
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   548
                        case Kinds.STATICERR:
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   549
                        case Kinds.MISSING_ENCL:
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   550
                           checkContext.report(null, diags.fragment("incompatible.arg.types.in.mref"));
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   551
                    }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   552
                }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   553
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   554
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   555
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   556
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   557
    /** an empty deferred attribution context - all methods throw exceptions */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   558
    final DeferredAttrContext emptyDeferredAttrContext =
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   559
            new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, null, null, null) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   560
                @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   561
                void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List<Type> stuckVars) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   562
                    Assert.error("Empty deferred context!");
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   563
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   564
                @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   565
                void complete() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   566
                    Assert.error("Empty deferred context!");
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   567
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   568
            };
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   569
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   570
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   571
     * Map a list of types possibly containing one or more deferred types
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   572
     * into a list of ordinary types. Each deferred type D is mapped into a type T,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   573
     * where T is computed by retrieving the type that has already been
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   574
     * computed for D during a previous deferred attribution round of the given kind.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   575
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   576
    class DeferredTypeMap extends Type.Mapping {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   577
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   578
        DeferredAttrContext deferredAttrContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   579
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   580
        protected DeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   581
            super(String.format("deferredTypeMap[%s]", mode));
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   582
            this.deferredAttrContext = new DeferredAttrContext(mode, msym, phase,
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   583
                    infer.emptyContext, emptyDeferredAttrContext, types.noWarnings);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   584
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   585
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   586
        protected boolean validState(DeferredType dt) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   587
            return dt.mode != null &&
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   588
                    deferredAttrContext.mode.ordinal() <= dt.mode.ordinal();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   589
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   590
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   591
        @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   592
        public Type apply(Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   593
            if (!t.hasTag(DEFERRED)) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   594
                return t.map(this);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   595
            } else {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   596
                DeferredType dt = (DeferredType)t;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   597
                Assert.check(validState(dt));
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   598
                return typeOf(dt);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   599
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   600
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   601
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   602
        protected Type typeOf(DeferredType dt) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   603
            switch (deferredAttrContext.mode) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   604
                case CHECK:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   605
                    return dt.tree.type == null ? Type.noType : dt.tree.type;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   606
                case SPECULATIVE:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   607
                    return dt.speculativeType(deferredAttrContext.msym, deferredAttrContext.phase);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   608
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   609
            Assert.error();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   610
            return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   611
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   612
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   613
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   614
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   615
     * Specialized recovery deferred mapping.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   616
     * Each deferred type D is mapped into a type T, where T is computed either by
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   617
     * (i) retrieving the type that has already been computed for D during a previous
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   618
     * attribution round (as before), or (ii) by synthesizing a new type R for D
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   619
     * (the latter step is useful in a recovery scenario).
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   620
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   621
    public class RecoveryDeferredTypeMap extends DeferredTypeMap {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   622
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   623
        public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   624
            super(mode, msym, phase != null ? phase : MethodResolutionPhase.BOX);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   625
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   626
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   627
        @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   628
        protected Type typeOf(DeferredType dt) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   629
            Type owntype = super.typeOf(dt);
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   630
            return owntype == Type.noType ?
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   631
                        recover(dt) : owntype;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   632
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   633
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   634
        @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   635
        protected boolean validState(DeferredType dt) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   636
            return true;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   637
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   638
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   639
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   640
         * Synthesize a type for a deferred type that hasn't been previously
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   641
         * reduced to an ordinary type. Functional deferred types and conditionals
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   642
         * are mapped to themselves, in order to have a richer diagnostic
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   643
         * representation. Remaining deferred types are attributed using
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   644
         * a default expected type (j.l.Object).
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   645
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   646
        private Type recover(DeferredType dt) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   647
            dt.check(attr.new RecoveryInfo(deferredAttrContext));
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   648
            return super.apply(dt);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   649
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   650
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   651
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   652
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   653
     * Retrieves the list of inference variables that need to be inferred before
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   654
     * an AST node can be type-checked
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   655
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   656
    @SuppressWarnings("fallthrough")
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   657
    List<Type> stuckVars(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   658
                if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   659
            return List.nil();
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   660
        } else {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   661
            return stuckVarsInternal(tree, resultInfo.pt, resultInfo.checkContext.inferenceContext());
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   662
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   663
    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   664
    //where
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   665
        private List<Type> stuckVarsInternal(JCTree tree, Type pt, Infer.InferenceContext inferenceContext) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   666
            StuckChecker sc = new StuckChecker(pt, inferenceContext);
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   667
            sc.scan(tree);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   668
            return List.from(sc.stuckVars);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   669
        }
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   670
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   671
    /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   672
     * A special tree scanner that would only visit portions of a given tree.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   673
     * The set of nodes visited by the scanner can be customized at construction-time.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   674
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   675
    abstract static class FilterScanner extends TreeScanner {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   676
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   677
        final Filter<JCTree> treeFilter;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   678
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   679
        FilterScanner(final Set<JCTree.Tag> validTags) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   680
            this.treeFilter = new Filter<JCTree>() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   681
                public boolean accepts(JCTree t) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   682
                    return validTags.contains(t.getTag());
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   683
                }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   684
            };
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   685
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   686
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   687
        @Override
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   688
        public void scan(JCTree tree) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   689
            if (tree != null) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   690
                if (treeFilter.accepts(tree)) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   691
                    super.scan(tree);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   692
                } else {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   693
                    skip(tree);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   694
                }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   695
            }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   696
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   697
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   698
        /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   699
         * handler that is executed when a node has been discarded
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   700
         */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   701
        abstract void skip(JCTree tree);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   702
    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   703
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   704
    /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   705
     * A tree scanner suitable for visiting the target-type dependent nodes of
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   706
     * a given argument expression.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   707
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   708
    static class PolyScanner extends FilterScanner {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   709
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   710
        PolyScanner() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   711
            super(EnumSet.of(CONDEXPR, PARENS, LAMBDA, REFERENCE));
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   712
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   713
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   714
        @Override
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   715
        void skip(JCTree tree) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   716
            //do nothing
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   717
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   718
    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   719
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   720
    /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   721
     * A tree scanner suitable for visiting the target-type dependent nodes nested
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   722
     * within a lambda expression body.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   723
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   724
    static class LambdaReturnScanner extends FilterScanner {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   725
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   726
        LambdaReturnScanner() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   727
            super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP,
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   728
                    FORLOOP, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP));
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   729
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   730
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   731
        @Override
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   732
        void skip(JCTree tree) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   733
            //do nothing
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   734
        }
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   735
    }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   736
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   737
    /**
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   738
     * This visitor is used to check that structural expressions conform
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   739
     * to their target - this step is required as inference could end up
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   740
     * inferring types that make some of the nested expressions incompatible
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   741
     * with their corresponding instantiated target
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   742
     */
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   743
    class StuckChecker extends PolyScanner {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   744
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   745
        Type pt;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   746
        Infer.InferenceContext inferenceContext;
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   747
        Set<Type> stuckVars = new LinkedHashSet<Type>();
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   748
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   749
        StuckChecker(Type pt, Infer.InferenceContext inferenceContext) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   750
            this.pt = pt;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   751
            this.inferenceContext = inferenceContext;
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   752
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   753
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   754
        @Override
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   755
        public void visitLambda(JCLambda tree) {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   756
            if (inferenceContext.inferenceVars().contains(pt)) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   757
                stuckVars.add(pt);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   758
            }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   759
            if (!types.isFunctionalInterface(pt)) {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   760
                return;
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   761
            }
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   762
            Type descType = types.findDescriptorType(pt);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   763
            List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   764
            if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT &&
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   765
                    freeArgVars.nonEmpty()) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   766
                stuckVars.addAll(freeArgVars);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   767
            }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   768
            scanLambdaBody(tree, descType.getReturnType());
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   769
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   770
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   771
        @Override
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   772
        public void visitReference(JCMemberReference tree) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   773
            scan(tree.expr);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   774
            if (inferenceContext.inferenceVars().contains(pt)) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   775
                stuckVars.add(pt);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   776
                return;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   777
            }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   778
            if (!types.isFunctionalInterface(pt)) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   779
                return;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   780
            }
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   781
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   782
            Type descType = types.findDescriptorType(pt);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   783
            List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   784
            stuckVars.addAll(freeArgVars);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   785
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   786
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   787
        void scanLambdaBody(JCLambda lambda, final Type pt) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   788
            if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   789
                stuckVars.addAll(stuckVarsInternal(lambda.body, pt, inferenceContext));
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   790
            } else {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   791
                LambdaReturnScanner lambdaScanner = new LambdaReturnScanner() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   792
                    @Override
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   793
                    public void visitReturn(JCReturn tree) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   794
                        if (tree.expr != null) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   795
                            stuckVars.addAll(stuckVarsInternal(tree.expr, pt, inferenceContext));
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   796
                        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   797
                    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   798
                };
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   799
                lambdaScanner.scan(lambda.body);
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   800
            }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   801
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   802
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   803
}