src/share/classes/com/sun/tools/javac/comp/Infer.java

changeset 1178
133744729455
parent 1127
ca49d50318dc
child 1186
51fb17abfc32
equal deleted inserted replaced
1177:70d92518063e 1178:133744729455
1 /* 1 /*
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 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. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
330 List<Type> targs = Type.map(undetvars, getInstFun); 330 List<Type> targs = Type.map(undetvars, getInstFun);
331 if (Type.containsAny(targs, that.tvars)) { 331 if (Type.containsAny(targs, that.tvars)) {
332 //replace uninferred type-vars 332 //replace uninferred type-vars
333 targs = types.subst(targs, 333 targs = types.subst(targs,
334 that.tvars, 334 that.tvars,
335 instaniateAsUninferredVars(undetvars, that.tvars)); 335 instantiateAsUninferredVars(undetvars, that.tvars));
336 } 336 }
337 return chk.checkType(warn.pos(), that.inst(targs, types), to); 337 return chk.checkType(warn.pos(), that.inst(targs, types), to);
338 } 338 }
339 //where 339 //where
340 private List<Type> instaniateAsUninferredVars(List<Type> undetvars, List<Type> tvars) { 340 private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
341 Assert.check(undetvars.length() == tvars.length());
341 ListBuffer<Type> new_targs = ListBuffer.lb(); 342 ListBuffer<Type> new_targs = ListBuffer.lb();
342 //step 1 - create syntethic captured vars 343 //step 1 - create synthetic captured vars
343 for (Type t : undetvars) { 344 for (Type t : undetvars) {
344 UndetVar uv = (UndetVar)t; 345 UndetVar uv = (UndetVar)t;
345 Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null); 346 Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null);
346 new_targs = new_targs.append(newArg); 347 new_targs = new_targs.append(newArg);
347 } 348 }
348 //step 2 - replace synthetic vars in their bounds 349 //step 2 - replace synthetic vars in their bounds
350 List<Type> formals = tvars;
349 for (Type t : new_targs.toList()) { 351 for (Type t : new_targs.toList()) {
350 CapturedType ct = (CapturedType)t; 352 CapturedType ct = (CapturedType)t;
351 ct.bound = types.subst(ct.bound, tvars, new_targs.toList()); 353 ct.bound = types.subst(ct.bound, tvars, new_targs.toList());
352 WildcardType wt = new WildcardType(ct.bound, BoundKind.EXTENDS, syms.boundClass); 354 WildcardType wt = new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass);
355 wt.bound = (TypeVar)formals.head;
353 ct.wildcard = wt; 356 ct.wildcard = wt;
357 formals = formals.tail;
354 } 358 }
355 return new_targs.toList(); 359 return new_targs.toList();
356 } 360 }
357 361
358 /** Instantiate method type `mt' by finding instantiations of 362 /** Instantiate method type `mt' by finding instantiations of

mercurial