diff --git a/src/Cryptol/TypeCheck/Infer.hs b/src/Cryptol/TypeCheck/Infer.hs index 8afde2818..3ec84b29c 100644 --- a/src/Cryptol/TypeCheck/Infer.hs +++ b/src/Cryptol/TypeCheck/Infer.hs @@ -642,7 +642,10 @@ inferCArm armNum (m : ms) = return (m1 : ms', Map.insertWith (\_ old -> old) x t ds, tMul n n') -- | @inferBinds isTopLevel isRec binds@ performs inference for a --- strongly-connected component of 'P.Bind's. If @isTopLevel@ is true, +-- strongly-connected component of 'P.Bind's. +-- If any of the members of the recursive group are already marked +-- as monomorphic, then we don't do generalzation. +-- If @isTopLevel@ is true, -- any bindings without type signatures will be generalized. If it is -- false, and the mono-binds flag is enabled, no bindings without type -- signatures will be generalized, but bindings with signatures will @@ -653,12 +656,11 @@ inferBinds isTopLevel isRec binds = -- declarations, mark all bindings lacking signatures as monomorphic monoBinds <- getMonoBinds let (sigs,noSigs) = partition (isJust . P.bSignature) binds - monos = [ b { P.bMono = True } | b <- noSigs ] - binds' | monoBinds && not isTopLevel = sigs ++ monos + monos = sigs ++ [ b { P.bMono = True } | b <- noSigs ] + binds' | any P.bMono binds = monos + | monoBinds && not isTopLevel = monos | otherwise = binds - - check exprMap = {- Guess type is here, because while we check user supplied signatures we may generate additional constraints. For example, `x - y` would diff --git a/tests/issues/issue607.icry b/tests/issues/issue607.icry new file mode 100644 index 000000000..b78169e8e --- /dev/null +++ b/tests/issues/issue607.icry @@ -0,0 +1,3 @@ +let (x,y)=(0,x+1) +x +y diff --git a/tests/issues/issue607.icry.stdout b/tests/issues/issue607.icry.stdout new file mode 100644 index 000000000..e66106cb1 --- /dev/null +++ b/tests/issues/issue607.icry.stdout @@ -0,0 +1,5 @@ +Loading module Cryptol +[warning] at :1:5--1:18: + Defaulting the type of '::y' to [1] +0x0 +0x1