[Nice-commit] Nice/src/nice/tools/typing Types.java,1.5,1.6
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-03-17 00:46:07
|
Update of /cvsroot/nice/Nice/src/nice/tools/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26138/src/nice/tools/typing Modified Files: Types.java Log Message: Do not allow overriding involving specialization of type parameters, as this is unsafe since dispatch does not consider type parameters. Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/typing/Types.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Types.java 2 Mar 2004 12:18:41 -0000 1.5 --- Types.java 17 Mar 2004 00:36:46 -0000 1.6 *************** *** 273,275 **** --- 273,324 ---- return true; } + + /** + @returns true if the spec type specializes type parameters of the original + type (which can not be checked at runtime during dispatch, and therefore + should not count as overriding). + */ + public static boolean typeParameterDispatch(Polytype spec, Polytype origin) + { + Monotype[] originalParams = parameters(origin); + + if (originalParams.length == 0) + return false; + + Typing.enter(); + try { + + try { + Polytype clonedSpec = spec.cloneType(); + + Constraint.enter(origin.getConstraint()); + Constraint.enter(clonedSpec.getConstraint()); + + // For all argument types ... + Monotype[] args = MonotypeVar.news(originalParams.length); + Typing.introduce(args); + + // ... that can be used for the first method ... + Typing.leq(args, originalParams); + + // ... and that will be dispatched to the specialized method ... + Typing.leqHead(args, parameters(clonedSpec)); + + Typing.implies(); + + // ... check that those args fit in the 'specialized' method ... + Constraint.enter(spec.getConstraint()); + Typing.leq(args, parameters(spec)); + } + finally { + Typing.leave(); + } + } + catch (TypingEx ex) { + return true; + } + + // OK, no covariant dispatch + return false; + } } |