Thu, 12 Jan 2012 15:28:34 +0000
7123100: javac fails with java.lang.StackOverflowError
Summary: Inference of under-constrained type-variables creates erroneous recursive wildcard types
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.comp;
28 import com.sun.tools.javac.tree.JCTree;
29 import com.sun.tools.javac.tree.JCTree.JCTypeCast;
30 import com.sun.tools.javac.tree.TreeInfo;
31 import com.sun.tools.javac.util.*;
32 import com.sun.tools.javac.util.List;
33 import com.sun.tools.javac.code.*;
34 import com.sun.tools.javac.code.Type.*;
35 import com.sun.tools.javac.code.Type.ForAll.ConstraintKind;
36 import com.sun.tools.javac.code.Symbol.*;
37 import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode;
38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
40 import static com.sun.tools.javac.code.TypeTags.*;
42 /** Helper class for type parameter inference, used by the attribution phase.
43 *
44 * <p><b>This is NOT part of any supported API.
45 * If you write code that depends on this, you do so at your own risk.
46 * This code and its internal interfaces are subject to change or
47 * deletion without notice.</b>
48 */
49 public class Infer {
50 protected static final Context.Key<Infer> inferKey =
51 new Context.Key<Infer>();
53 /** A value for prototypes that admit any type, including polymorphic ones. */
54 public static final Type anyPoly = new Type(NONE, null);
56 Symtab syms;
57 Types types;
58 Check chk;
59 Resolve rs;
60 Log log;
61 JCDiagnostic.Factory diags;
63 public static Infer instance(Context context) {
64 Infer instance = context.get(inferKey);
65 if (instance == null)
66 instance = new Infer(context);
67 return instance;
68 }
70 protected Infer(Context context) {
71 context.put(inferKey, this);
72 syms = Symtab.instance(context);
73 types = Types.instance(context);
74 rs = Resolve.instance(context);
75 log = Log.instance(context);
76 chk = Check.instance(context);
77 diags = JCDiagnostic.Factory.instance(context);
78 ambiguousNoInstanceException =
79 new NoInstanceException(true, diags);
80 unambiguousNoInstanceException =
81 new NoInstanceException(false, diags);
82 invalidInstanceException =
83 new InvalidInstanceException(diags);
85 }
87 public static class InferenceException extends Resolve.InapplicableMethodException {
88 private static final long serialVersionUID = 0;
90 InferenceException(JCDiagnostic.Factory diags) {
91 super(diags);
92 }
93 }
95 public static class NoInstanceException extends InferenceException {
96 private static final long serialVersionUID = 1;
98 boolean isAmbiguous; // exist several incomparable best instances?
100 NoInstanceException(boolean isAmbiguous, JCDiagnostic.Factory diags) {
101 super(diags);
102 this.isAmbiguous = isAmbiguous;
103 }
104 }
106 public static class InvalidInstanceException extends InferenceException {
107 private static final long serialVersionUID = 2;
109 InvalidInstanceException(JCDiagnostic.Factory diags) {
110 super(diags);
111 }
112 }
114 private final NoInstanceException ambiguousNoInstanceException;
115 private final NoInstanceException unambiguousNoInstanceException;
116 private final InvalidInstanceException invalidInstanceException;
118 /***************************************************************************
119 * Auxiliary type values and classes
120 ***************************************************************************/
122 /** A mapping that turns type variables into undetermined type variables.
123 */
124 Mapping fromTypeVarFun = new Mapping("fromTypeVarFun") {
125 public Type apply(Type t) {
126 if (t.tag == TYPEVAR) return new UndetVar(t);
127 else return t.map(this);
128 }
129 };
131 /** A mapping that returns its type argument with every UndetVar replaced
132 * by its `inst' field. Throws a NoInstanceException
133 * if this not possible because an `inst' field is null.
134 * Note: mutually referring undertvars will be left uninstantiated
135 * (that is, they will be replaced by the underlying type-variable).
136 */
138 Mapping getInstFun = new Mapping("getInstFun") {
139 public Type apply(Type t) {
140 switch (t.tag) {
141 case UNKNOWN:
142 throw ambiguousNoInstanceException
143 .setMessage("undetermined.type");
144 case UNDETVAR:
145 UndetVar that = (UndetVar) t;
146 if (that.inst == null)
147 throw ambiguousNoInstanceException
148 .setMessage("type.variable.has.undetermined.type",
149 that.qtype);
150 return isConstraintCyclic(that) ?
151 that.qtype :
152 apply(that.inst);
153 default:
154 return t.map(this);
155 }
156 }
158 private boolean isConstraintCyclic(UndetVar uv) {
159 Types.UnaryVisitor<Boolean> constraintScanner =
160 new Types.UnaryVisitor<Boolean>() {
162 List<Type> seen = List.nil();
164 Boolean visit(List<Type> ts) {
165 for (Type t : ts) {
166 if (visit(t)) return true;
167 }
168 return false;
169 }
171 public Boolean visitType(Type t, Void ignored) {
172 return false;
173 }
175 @Override
176 public Boolean visitClassType(ClassType t, Void ignored) {
177 if (t.isCompound()) {
178 return visit(types.supertype(t)) ||
179 visit(types.interfaces(t));
180 } else {
181 return visit(t.getTypeArguments());
182 }
183 }
184 @Override
185 public Boolean visitWildcardType(WildcardType t, Void ignored) {
186 return visit(t.type);
187 }
189 @Override
190 public Boolean visitUndetVar(UndetVar t, Void ignored) {
191 if (seen.contains(t)) {
192 return true;
193 } else {
194 seen = seen.prepend(t);
195 return visit(t.inst);
196 }
197 }
198 };
199 return constraintScanner.visit(uv);
200 }
201 };
203 /***************************************************************************
204 * Mini/Maximization of UndetVars
205 ***************************************************************************/
207 /** Instantiate undetermined type variable to its minimal upper bound.
208 * Throw a NoInstanceException if this not possible.
209 */
210 void maximizeInst(UndetVar that, Warner warn) throws NoInstanceException {
211 List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
212 if (that.inst == null) {
213 if (hibounds.isEmpty())
214 that.inst = syms.objectType;
215 else if (hibounds.tail.isEmpty())
216 that.inst = hibounds.head;
217 else
218 that.inst = types.glb(hibounds);
219 }
220 if (that.inst == null ||
221 that.inst.isErroneous())
222 throw ambiguousNoInstanceException
223 .setMessage("no.unique.maximal.instance.exists",
224 that.qtype, hibounds);
225 }
226 //where
227 private boolean isSubClass(Type t, final List<Type> ts) {
228 t = t.baseType();
229 if (t.tag == TYPEVAR) {
230 List<Type> bounds = types.getBounds((TypeVar)t);
231 for (Type s : ts) {
232 if (!types.isSameType(t, s.baseType())) {
233 for (Type bound : bounds) {
234 if (!isSubClass(bound, List.of(s.baseType())))
235 return false;
236 }
237 }
238 }
239 } else {
240 for (Type s : ts) {
241 if (!t.tsym.isSubClass(s.baseType().tsym, types))
242 return false;
243 }
244 }
245 return true;
246 }
248 private Filter<Type> errorFilter = new Filter<Type>() {
249 @Override
250 public boolean accepts(Type t) {
251 return !t.isErroneous();
252 }
253 };
255 /** Instantiate undetermined type variable to the lub of all its lower bounds.
256 * Throw a NoInstanceException if this not possible.
257 */
258 void minimizeInst(UndetVar that, Warner warn) throws NoInstanceException {
259 List<Type> lobounds = Type.filter(that.lobounds, errorFilter);
260 if (that.inst == null) {
261 if (lobounds.isEmpty())
262 that.inst = syms.botType;
263 else if (lobounds.tail.isEmpty())
264 that.inst = lobounds.head.isPrimitive() ? syms.errType : lobounds.head;
265 else {
266 that.inst = types.lub(lobounds);
267 }
268 if (that.inst == null || that.inst.tag == ERROR)
269 throw ambiguousNoInstanceException
270 .setMessage("no.unique.minimal.instance.exists",
271 that.qtype, lobounds);
272 // VGJ: sort of inlined maximizeInst() below. Adding
273 // bounds can cause lobounds that are above hibounds.
274 List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
275 Type hb = null;
276 if (hibounds.isEmpty())
277 hb = syms.objectType;
278 else if (hibounds.tail.isEmpty())
279 hb = hibounds.head;
280 else
281 hb = types.glb(hibounds);
282 if (hb == null ||
283 hb.isErroneous())
284 throw ambiguousNoInstanceException
285 .setMessage("incompatible.upper.bounds",
286 that.qtype, hibounds);
287 }
288 }
290 /***************************************************************************
291 * Exported Methods
292 ***************************************************************************/
294 /** Try to instantiate expression type `that' to given type `to'.
295 * If a maximal instantiation exists which makes this type
296 * a subtype of type `to', return the instantiated type.
297 * If no instantiation exists, or if several incomparable
298 * best instantiations exist throw a NoInstanceException.
299 */
300 public Type instantiateExpr(ForAll that,
301 Type to,
302 Warner warn) throws InferenceException {
303 List<Type> undetvars = Type.map(that.tvars, fromTypeVarFun);
304 for (List<Type> l = undetvars; l.nonEmpty(); l = l.tail) {
305 UndetVar uv = (UndetVar) l.head;
306 TypeVar tv = (TypeVar)uv.qtype;
307 ListBuffer<Type> hibounds = new ListBuffer<Type>();
308 for (Type t : that.getConstraints(tv, ConstraintKind.EXTENDS)) {
309 hibounds.append(types.subst(t, that.tvars, undetvars));
310 }
312 List<Type> inst = that.getConstraints(tv, ConstraintKind.EQUAL);
313 if (inst.nonEmpty() && inst.head.tag != BOT) {
314 uv.inst = inst.head;
315 }
316 uv.hibounds = hibounds.toList();
317 }
318 Type qtype1 = types.subst(that.qtype, that.tvars, undetvars);
319 if (!types.isSubtype(qtype1,
320 qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) {
321 throw unambiguousNoInstanceException
322 .setMessage("infer.no.conforming.instance.exists",
323 that.tvars, that.qtype, to);
324 }
325 for (List<Type> l = undetvars; l.nonEmpty(); l = l.tail)
326 maximizeInst((UndetVar) l.head, warn);
327 // System.out.println(" = " + qtype1.map(getInstFun));//DEBUG
329 // check bounds
330 List<Type> targs = Type.map(undetvars, getInstFun);
331 if (Type.containsAny(targs, that.tvars)) {
332 //replace uninferred type-vars
333 targs = types.subst(targs,
334 that.tvars,
335 instantiateAsUninferredVars(undetvars, that.tvars));
336 }
337 return chk.checkType(warn.pos(), that.inst(targs, types), to);
338 }
339 //where
340 private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
341 Assert.check(undetvars.length() == tvars.length());
342 ListBuffer<Type> new_targs = ListBuffer.lb();
343 //step 1 - create synthetic captured vars
344 for (Type t : undetvars) {
345 UndetVar uv = (UndetVar)t;
346 Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null);
347 new_targs = new_targs.append(newArg);
348 }
349 //step 2 - replace synthetic vars in their bounds
350 List<Type> formals = tvars;
351 for (Type t : new_targs.toList()) {
352 CapturedType ct = (CapturedType)t;
353 ct.bound = types.subst(ct.bound, tvars, new_targs.toList());
354 WildcardType wt = new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass);
355 wt.bound = (TypeVar)formals.head;
356 ct.wildcard = wt;
357 formals = formals.tail;
358 }
359 return new_targs.toList();
360 }
362 /** Instantiate method type `mt' by finding instantiations of
363 * `tvars' so that method can be applied to `argtypes'.
364 */
365 public Type instantiateMethod(final Env<AttrContext> env,
366 List<Type> tvars,
367 MethodType mt,
368 final Symbol msym,
369 final List<Type> argtypes,
370 final boolean allowBoxing,
371 final boolean useVarargs,
372 final Warner warn) throws InferenceException {
373 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
374 List<Type> undetvars = Type.map(tvars, fromTypeVarFun);
375 List<Type> formals = mt.argtypes;
376 //need to capture exactly once - otherwise subsequent
377 //applicability checks might fail
378 final List<Type> capturedArgs = types.capture(argtypes);
379 List<Type> actuals = capturedArgs;
380 List<Type> actualsNoCapture = argtypes;
381 // instantiate all polymorphic argument types and
382 // set up lower bounds constraints for undetvars
383 Type varargsFormal = useVarargs ? formals.last() : null;
384 if (varargsFormal == null &&
385 actuals.size() != formals.size()) {
386 throw unambiguousNoInstanceException
387 .setMessage("infer.arg.length.mismatch");
388 }
389 while (actuals.nonEmpty() && formals.head != varargsFormal) {
390 Type formal = formals.head;
391 Type actual = actuals.head.baseType();
392 Type actualNoCapture = actualsNoCapture.head.baseType();
393 if (actual.tag == FORALL)
394 actual = instantiateArg((ForAll)actual, formal, tvars, warn);
395 Type undetFormal = types.subst(formal, tvars, undetvars);
396 boolean works = allowBoxing
397 ? types.isConvertible(actual, undetFormal, warn)
398 : types.isSubtypeUnchecked(actual, undetFormal, warn);
399 if (!works) {
400 throw unambiguousNoInstanceException
401 .setMessage("infer.no.conforming.assignment.exists",
402 tvars, actualNoCapture, formal);
403 }
404 formals = formals.tail;
405 actuals = actuals.tail;
406 actualsNoCapture = actualsNoCapture.tail;
407 }
409 if (formals.head != varargsFormal) // not enough args
410 throw unambiguousNoInstanceException.setMessage("infer.arg.length.mismatch");
412 // for varargs arguments as well
413 if (useVarargs) {
414 Type elemType = types.elemtype(varargsFormal);
415 Type elemUndet = types.subst(elemType, tvars, undetvars);
416 while (actuals.nonEmpty()) {
417 Type actual = actuals.head.baseType();
418 Type actualNoCapture = actualsNoCapture.head.baseType();
419 if (actual.tag == FORALL)
420 actual = instantiateArg((ForAll)actual, elemType, tvars, warn);
421 boolean works = types.isConvertible(actual, elemUndet, warn);
422 if (!works) {
423 throw unambiguousNoInstanceException
424 .setMessage("infer.no.conforming.assignment.exists",
425 tvars, actualNoCapture, elemType);
426 }
427 actuals = actuals.tail;
428 actualsNoCapture = actualsNoCapture.tail;
429 }
430 }
432 // minimize as yet undetermined type variables
433 for (Type t : undetvars)
434 minimizeInst((UndetVar) t, warn);
436 /** Type variables instantiated to bottom */
437 ListBuffer<Type> restvars = new ListBuffer<Type>();
439 /** Undet vars instantiated to bottom */
440 final ListBuffer<Type> restundet = new ListBuffer<Type>();
442 /** Instantiated types or TypeVars if under-constrained */
443 ListBuffer<Type> insttypes = new ListBuffer<Type>();
445 /** Instantiated types or UndetVars if under-constrained */
446 ListBuffer<Type> undettypes = new ListBuffer<Type>();
448 for (Type t : undetvars) {
449 UndetVar uv = (UndetVar)t;
450 if (uv.inst.tag == BOT) {
451 restvars.append(uv.qtype);
452 restundet.append(uv);
453 insttypes.append(uv.qtype);
454 undettypes.append(uv);
455 uv.inst = null;
456 } else {
457 insttypes.append(uv.inst);
458 undettypes.append(uv.inst);
459 }
460 }
461 checkWithinBounds(tvars, undettypes.toList(), warn);
463 mt = (MethodType)types.subst(mt, tvars, insttypes.toList());
465 if (!restvars.isEmpty()) {
466 // if there are uninstantiated variables,
467 // quantify result type with them
468 final List<Type> inferredTypes = insttypes.toList();
469 final List<Type> all_tvars = tvars; //this is the wrong tvars
470 return new UninferredMethodType(env.tree.pos(), msym, mt, restvars.toList()) {
471 @Override
472 List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
473 for (Type t : restundet.toList()) {
474 UndetVar uv = (UndetVar)t;
475 if (uv.qtype == tv) {
476 switch (ck) {
477 case EXTENDS: return uv.hibounds.appendList(types.subst(types.getBounds(tv), all_tvars, inferredTypes));
478 case SUPER: return uv.lobounds;
479 case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil();
480 }
481 }
482 }
483 return List.nil();
484 }
485 @Override
486 void check(List<Type> inferred, Types types) throws NoInstanceException {
487 // check that actuals conform to inferred formals
488 checkArgumentsAcceptable(env, capturedArgs, getParameterTypes(), allowBoxing, useVarargs, warn);
489 // check that inferred bounds conform to their bounds
490 checkWithinBounds(all_tvars,
491 types.subst(inferredTypes, tvars, inferred), warn);
492 if (useVarargs) {
493 chk.checkVararg(env.tree.pos(), getParameterTypes(), msym);
494 }
495 }};
496 }
497 else {
498 // check that actuals conform to inferred formals
499 checkArgumentsAcceptable(env, capturedArgs, mt.getParameterTypes(), allowBoxing, useVarargs, warn);
500 // return instantiated version of method type
501 return mt;
502 }
503 }
504 //where
506 /**
507 * A delegated type representing a partially uninferred method type.
508 * The return type of a partially uninferred method type is a ForAll
509 * type - when the return type is instantiated (see Infer.instantiateExpr)
510 * the underlying method type is also updated.
511 */
512 abstract class UninferredMethodType extends DelegatedType {
514 final List<Type> tvars;
515 final Symbol msym;
516 final DiagnosticPosition pos;
518 public UninferredMethodType(DiagnosticPosition pos, Symbol msym, MethodType mtype, List<Type> tvars) {
519 super(METHOD, new MethodType(mtype.argtypes, null, mtype.thrown, mtype.tsym));
520 this.tvars = tvars;
521 this.msym = msym;
522 this.pos = pos;
523 asMethodType().restype = new UninferredReturnType(tvars, mtype.restype);
524 }
526 @Override
527 public MethodType asMethodType() {
528 return qtype.asMethodType();
529 }
531 @Override
532 public Type map(Mapping f) {
533 return qtype.map(f);
534 }
536 void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
537 //update method type with newly inferred type-arguments
538 qtype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
539 restype,
540 types.subst(UninferredMethodType.this.getThrownTypes(), tvars, inferred),
541 UninferredMethodType.this.qtype.tsym);
542 check(inferred, types);
543 }
545 abstract void check(List<Type> inferred, Types types) throws NoInstanceException;
547 abstract List<Type> getConstraints(TypeVar tv, ConstraintKind ck);
549 class UninferredReturnType extends ForAll {
550 public UninferredReturnType(List<Type> tvars, Type restype) {
551 super(tvars, restype);
552 }
553 @Override
554 public Type inst(List<Type> actuals, Types types) {
555 Type newRestype = super.inst(actuals, types);
556 instantiateReturnType(newRestype, actuals, types);
557 if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
558 log.note(pos, "deferred.method.inst", msym, UninferredMethodType.this.qtype, newRestype);
559 }
560 return newRestype;
561 }
562 @Override
563 public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
564 return UninferredMethodType.this.getConstraints(tv, ck);
565 }
566 }
567 }
569 private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals,
570 boolean allowBoxing, boolean useVarargs, Warner warn) {
571 try {
572 rs.checkRawArgumentsAcceptable(env, actuals, formals,
573 allowBoxing, useVarargs, warn);
574 }
575 catch (Resolve.InapplicableMethodException ex) {
576 // inferred method is not applicable
577 throw invalidInstanceException.setMessage(ex.getDiagnostic());
578 }
579 }
581 /** Try to instantiate argument type `that' to given type `to'.
582 * If this fails, try to insantiate `that' to `to' where
583 * every occurrence of a type variable in `tvars' is replaced
584 * by an unknown type.
585 */
586 private Type instantiateArg(ForAll that,
587 Type to,
588 List<Type> tvars,
589 Warner warn) throws InferenceException {
590 List<Type> targs;
591 try {
592 return instantiateExpr(that, to, warn);
593 } catch (NoInstanceException ex) {
594 Type to1 = to;
595 for (List<Type> l = tvars; l.nonEmpty(); l = l.tail)
596 to1 = types.subst(to1, List.of(l.head), List.of(syms.unknownType));
597 return instantiateExpr(that, to1, warn);
598 }
599 }
601 /** check that type parameters are within their bounds.
602 */
603 void checkWithinBounds(List<Type> tvars,
604 List<Type> arguments,
605 Warner warn)
606 throws InvalidInstanceException {
607 for (List<Type> tvs = tvars, args = arguments;
608 tvs.nonEmpty();
609 tvs = tvs.tail, args = args.tail) {
610 if (args.head instanceof UndetVar ||
611 tvars.head.getUpperBound().isErroneous()) continue;
612 List<Type> bounds = types.subst(types.getBounds((TypeVar)tvs.head), tvars, arguments);
613 if (!types.isSubtypeUnchecked(args.head, bounds, warn))
614 throw invalidInstanceException
615 .setMessage("inferred.do.not.conform.to.bounds",
616 args.head, bounds);
617 }
618 }
620 /**
621 * Compute a synthetic method type corresponding to the requested polymorphic
622 * method signature. The target return type is computed from the immediately
623 * enclosing scope surrounding the polymorphic-signature call.
624 */
625 Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
626 Name name,
627 MethodSymbol spMethod, // sig. poly. method or null if none
628 List<Type> argtypes) {
629 final Type restype;
631 //The return type for a polymorphic signature call is computed from
632 //the enclosing tree E, as follows: if E is a cast, then use the
633 //target type of the cast expression as a return type; if E is an
634 //expression statement, the return type is 'void' - otherwise the
635 //return type is simply 'Object'. A correctness check ensures that
636 //env.next refers to the lexically enclosing environment in which
637 //the polymorphic signature call environment is nested.
639 switch (env.next.tree.getTag()) {
640 case TYPECAST:
641 JCTypeCast castTree = (JCTypeCast)env.next.tree;
642 restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
643 castTree.clazz.type :
644 syms.objectType;
645 break;
646 case EXEC:
647 JCTree.JCExpressionStatement execTree =
648 (JCTree.JCExpressionStatement)env.next.tree;
649 restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
650 syms.voidType :
651 syms.objectType;
652 break;
653 default:
654 restype = syms.objectType;
655 }
657 List<Type> paramtypes = Type.map(argtypes, implicitArgType);
658 List<Type> exType = spMethod != null ?
659 spMethod.getThrownTypes() :
660 List.of(syms.throwableType); // make it throw all exceptions
662 MethodType mtype = new MethodType(paramtypes,
663 restype,
664 exType,
665 syms.methodClass);
666 return mtype;
667 }
668 //where
669 Mapping implicitArgType = new Mapping ("implicitArgType") {
670 public Type apply(Type t) {
671 t = types.erasure(t);
672 if (t.tag == BOT)
673 // nulls type as the marker type Null (which has no instances)
674 // infer as java.lang.Void for now
675 t = types.boxedClass(syms.voidType).type;
676 return t;
677 }
678 };
679 }