diff --git a/CHANGELOG.md b/CHANGELOG.md index ea8971b62d..d6bc198343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Error in type checking of horisontally fused `scatter`s could crash the compiler (#2009). +* Size-polymorphic value bindings with existential sizes are now + rejected by type checker (#1993). + ## [0.25.2] ### Added diff --git a/src/Language/Futhark/TypeChecker/Terms.hs b/src/Language/Futhark/TypeChecker/Terms.hs index 54a2d0e7cf..195ca81c2d 100644 --- a/src/Language/Futhark/TypeChecker/Terms.hs +++ b/src/Language/Futhark/TypeChecker/Terms.hs @@ -1480,6 +1480,18 @@ checkBinding (fname, maybe_retdecl, tparams, params, body, loc) = letGeneralise fname loc tparams' params'' =<< unscopeUnknown rettype + when + ( null params + && any isSizeParam tparams'' + && not (null (retDims rettype')) + ) + $ typeError loc mempty + $ textwrap "A size-polymorphic value binding may not have a type with an existential size." + "Type of this binding is:" + indent 2 (pretty rettype') + "with the following type parameters:" + indent 2 (sep $ map pretty $ filter isSizeParam tparams'') + pure (tparams'', params''', maybe_retdecl'', rettype', body') -- | Extract all the shape names that occur in positive position diff --git a/tests/shapes/toplevel2.fut b/tests/shapes/toplevel2.fut new file mode 100644 index 0000000000..1aea78c37f --- /dev/null +++ b/tests/shapes/toplevel2.fut @@ -0,0 +1,6 @@ +-- #1993, do not allow size-polymorphic non-function bindings with +-- unknown sizes. +-- == +-- error: size-polymorphic value binding + +def foo [n] = (iota n, filter (>5) (iota n))