Skip to content

Commit

Permalink
Fix compiler crash when a type operator is used in a type argument (#…
Browse files Browse the repository at this point in the history
…4536)

Add missing traversal branch for VisibleTypeApp in updateTypes
  • Loading branch information
purefunctor committed Feb 26, 2024
1 parent 5589e81 commit debfc2e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.d/fix_issue-4535.md
@@ -0,0 +1 @@
* Fix compiler crash when a type operator is used in a type argument
3 changes: 3 additions & 0 deletions src/Language/PureScript/Sugar/Operators.hs
Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions 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"

0 comments on commit debfc2e

Please sign in to comment.