From debfc2e4e1e859bde3f679850767acd545a0d0f4 Mon Sep 17 00:00:00 2001 From: Justin Garcia Date: Tue, 27 Feb 2024 03:16:09 +0800 Subject: [PATCH] Fix compiler crash when a type operator is used in a type argument (#4536) Add missing traversal branch for VisibleTypeApp in updateTypes --- CHANGELOG.d/fix_issue-4535.md | 1 + src/Language/PureScript/Sugar/Operators.hs | 3 ++ tests/purs/passing/4535.purs | 43 ++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 CHANGELOG.d/fix_issue-4535.md create mode 100644 tests/purs/passing/4535.purs diff --git a/CHANGELOG.d/fix_issue-4535.md b/CHANGELOG.d/fix_issue-4535.md new file mode 100644 index 0000000000..77341885a9 --- /dev/null +++ b/CHANGELOG.d/fix_issue-4535.md @@ -0,0 +1 @@ +* Fix compiler crash when a type operator is used in a type argument diff --git a/src/Language/PureScript/Sugar/Operators.hs b/src/Language/PureScript/Sugar/Operators.hs index bb06486e82..93028d7e22 100644 --- a/src/Language/PureScript/Sugar/Operators.hs +++ b/src/Language/PureScript/Sugar/Operators.hs @@ -409,6 +409,9 @@ updateTypes goType = (goDecl, goExpr, goBinder) goExpr pos (TypedValue check v ty) = do ty' <- goType' pos ty return (pos, TypedValue check v ty') + goExpr pos (VisibleTypeApp v ty) = do + ty' <- goType' pos ty + return (pos, VisibleTypeApp v ty') goExpr pos other = return (pos, other) goBinder :: SourceSpan -> Binder -> m (SourceSpan, Binder) diff --git a/tests/purs/passing/4535.purs b/tests/purs/passing/4535.purs new file mode 100644 index 0000000000..424ba6e7e5 --- /dev/null +++ b/tests/purs/passing/4535.purs @@ -0,0 +1,43 @@ +module Main where + +import Prelude + +import Data.Maybe (Maybe(..)) +import Data.Tuple.Nested ((/\), type (/\)) +import Effect (Effect) +import Effect.Console (log) +import Type.Proxy (Proxy(..)) + +singleArgument :: forall @a. a -> Unit +singleArgument _ = unit + +multiArgument :: forall @a @b. a -> b -> Unit +multiArgument _ _ = unit + +singleApplication :: Int /\ Number -> Unit +singleApplication = singleArgument @(Int /\ Number) + +-- Like expression applications, visible type applications are left-associative. +-- This test accounts for subsequent type applications nested in this manner. +appNestingWorks :: Int /\ Number -> Number /\ Int -> Unit +appNestingWorks = multiArgument @(Int /\ Number) @(Number /\ Int) + +-- This test accounts for type applications nested within other AST nodes. +otherNestingWorks :: Array (Maybe (Int /\ Number)) +otherNestingWorks = [Just @(Int /\ Number) (0 /\ 0.0), Just @(Int /\ Number) (1 /\ 1.0)] + +type InSynonym = Int /\ Number + +-- This test accounts for type synonyms used as type arguments. +-- Since expansion happens during checking, InSynonym would expand +-- to an already-desugared type operator. This test exists for the +-- sake of redundancy. +inSynonym :: InSynonym -> Unit +inSynonym = singleArgument @InSynonym + +-- This test accounts for type operators used as type arguments directly. +operatorAsArgument :: Proxy (/\) +operatorAsArgument = Proxy @(/\) + +main :: Effect Unit +main = log "Done"