[Nice-commit] Nice/src/bossa/syntax typecheck.nice,1.50,1.51 Function.java,1.5,1.6 FunExp.java,1.38,
Brought to you by:
bonniot
From: <bo...@us...> - 2003-02-26 17:09:33
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv1298/src/bossa/syntax Modified Files: typecheck.nice Function.java FunExp.java Log Message: Check that the different returns in an anonymous function form build a well-formed type (fixes #693184). Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** typecheck.nice 18 Feb 2003 23:39:44 -0000 1.50 --- typecheck.nice 26 Feb 2003 17:09:24 -0000 1.51 *************** *** 547,550 **** --- 547,553 ---- valueOf(e.expectedReturnType), notNull(e.typingException)); } + catch(Function.IncompatibleReturnType e){ + throw bossa.util.User.error(r, "The returned value is incompatible with the return type: " + e.previouslyInferredType); + } } Index: Function.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Function.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Function.java 18 Sep 2002 19:30:42 -0000 1.5 --- Function.java 26 Feb 2003 17:09:25 -0000 1.6 *************** *** 2,6 **** /* N I C E */ /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2000 */ /* */ /* This program is free software; you can redistribute it and/or modify */ --- 2,6 ---- /* N I C E */ /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2003 */ /* */ /* This program is free software; you can redistribute it and/or modify */ *************** *** 17,28 **** @version $Date$ ! @author Daniel Bonniot (d.b...@ma...) */ interface Function { /** The expected return type of this function. ! Can be null if it is not know (e.g. the type is inferred). */ mlsub.typing.Monotype getExpectedType(); --- 17,30 ---- @version $Date$ ! @author Daniel Bonniot (bo...@us...) */ + import mlsub.typing.Polytype; + interface Function { /** The expected return type of this function. ! Can be null if it is not known (e.g. the type is inferred). */ mlsub.typing.Monotype getExpectedType(); *************** *** 33,39 **** */ void checkReturnedType(mlsub.typing.Polytype returned) ! throws WrongReturnType; ! class WrongReturnType extends Exception { WrongReturnType(mlsub.typing.TypingEx typingException, --- 35,43 ---- */ void checkReturnedType(mlsub.typing.Polytype returned) ! throws ReturnTypeError; ! abstract class ReturnTypeError extends Exception {} ! ! class WrongReturnType extends ReturnTypeError { WrongReturnType(mlsub.typing.TypingEx typingException, *************** *** 46,49 **** --- 50,63 ---- mlsub.typing.TypingEx typingException; mlsub.typing.Monotype expectedReturnType; + } + + static class IncompatibleReturnType extends ReturnTypeError + { + IncompatibleReturnType(Polytype previouslyInferredType) + { + this.previouslyInferredType = previouslyInferredType; + } + + Polytype previouslyInferredType; } } Index: FunExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/FunExp.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** FunExp.java 17 Feb 2003 14:15:40 -0000 1.38 --- FunExp.java 26 Feb 2003 17:09:25 -0000 1.39 *************** *** 55,64 **** public void checkReturnedType(mlsub.typing.Polytype returned) ! throws Function.WrongReturnType { if (inferredReturnType == null) inferredReturnType = returned; else ! inferredReturnType = Polytype.union(inferredReturnType, returned); /* This is disabled, since currently default values of class fields are --- 55,70 ---- public void checkReturnedType(mlsub.typing.Polytype returned) ! throws Function.ReturnTypeError { if (inferredReturnType == null) inferredReturnType = returned; else ! { ! Polytype old = inferredReturnType; ! inferredReturnType = Polytype.union(inferredReturnType, returned); ! ! if (! inferredReturnType.trySimplify()) ! throw new FunExp.IncompatibleReturnType(old); ! } /* This is disabled, since currently default values of class fields are *************** *** 81,86 **** ! nice.tools.code.Types.isVoid(inferredReturnType)) throw User.error(this, "Missing return statement"); - - inferredReturnType.simplify(); Monotype t = new FunType(MonoSymbol.getMonotype(formals), --- 87,90 ---- |