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

changeset 59
4a3b9801f7a0
parent 42
f7e64b33d5a4
child 60
29d2485c1085
equal deleted inserted replaced
58:8bc2ca2a3b0a 59:4a3b9801f7a0
1365 Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1); 1365 Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1);
1366 boolean compat = 1366 boolean compat =
1367 types.isSameType(rt1, rt2) || 1367 types.isSameType(rt1, rt2) ||
1368 rt1.tag >= CLASS && rt2.tag >= CLASS && 1368 rt1.tag >= CLASS && rt2.tag >= CLASS &&
1369 (types.covariantReturnType(rt1, rt2, Warner.noWarnings) || 1369 (types.covariantReturnType(rt1, rt2, Warner.noWarnings) ||
1370 types.covariantReturnType(rt2, rt1, Warner.noWarnings)); 1370 types.covariantReturnType(rt2, rt1, Warner.noWarnings)) ||
1371 checkCommonOverriderIn(s1,s2,site);
1371 if (!compat) return s2; 1372 if (!compat) return s2;
1372 } 1373 }
1373 } 1374 }
1374 } 1375 }
1375 return null; 1376 return null;
1377 }
1378 //WHERE
1379 boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) {
1380 Map<TypeSymbol,Type> supertypes = new HashMap<TypeSymbol,Type>();
1381 Type st1 = types.memberType(site, s1);
1382 Type st2 = types.memberType(site, s2);
1383 closure(site, supertypes);
1384 for (Type t : supertypes.values()) {
1385 for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) {
1386 Symbol s3 = e.sym;
1387 if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue;
1388 Type st3 = types.memberType(site,s3);
1389 if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2)) {
1390 if (s3.owner == site.tsym) {
1391 return true;
1392 }
1393 List<Type> tvars1 = st1.getTypeArguments();
1394 List<Type> tvars2 = st2.getTypeArguments();
1395 List<Type> tvars3 = st3.getTypeArguments();
1396 Type rt1 = st1.getReturnType();
1397 Type rt2 = st2.getReturnType();
1398 Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1);
1399 Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2);
1400 boolean compat =
1401 rt13.tag >= CLASS && rt23.tag >= CLASS &&
1402 (types.covariantReturnType(rt13, rt1, Warner.noWarnings) &&
1403 types.covariantReturnType(rt23, rt2, Warner.noWarnings));
1404 if (compat)
1405 return true;
1406 }
1407 }
1408 }
1409 return false;
1376 } 1410 }
1377 1411
1378 /** Check that a given method conforms with any method it overrides. 1412 /** Check that a given method conforms with any method it overrides.
1379 * @param tree The tree from which positions are extracted 1413 * @param tree The tree from which positions are extracted
1380 * for errors. 1414 * for errors.

mercurial