Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Internal/Arg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,20 @@ aliasAs aliasName (Arg toArgDetails) =
innerArgDetails =
toArgDetails index

( aliasVal, _, _ ) =
val innerArgDetails.index aliasName
-- The alias refers to the same value as the underlying
-- pattern, so it should have the same type. Use the
-- inner pattern's annotation (the record type, tuple
-- type, etc.) rather than creating a fresh type variable.
aliasVal : Compiler.Expression
aliasVal =
Compiler.Expression <|
\_ ->
{ expression =
Exp.FunctionOrValue []
(Format.sanitize aliasName)
, annotation = innerArgDetails.details.annotation
, imports = []
}
in
{ details =
{ imports = innerArgDetails.details.imports
Expand Down
18 changes: 18 additions & 0 deletions tests/TypeChecking.elm
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ generatedCode =
( 1 + 2, x )
"""
]
, describe "aliasAs pattern type"
[ test "aliasAs on record pattern uses the underlying record type" <|
\_ ->
Elm.Declare.fn "describe"
(Arg.record (\a b -> ( a, b ))
|> Arg.field "name"
|> Arg.field "age"
|> Arg.aliasAs "person"
)
(\( ( name, _ ), person ) ->
Elm.tuple name person
)
|> .declaration
|> Elm.Expect.declarationAs
"""
describe : { name : name, age : age } -> ( name, { name : name, age : age } )
describe ({ name, age } as person) =
( name, person )
, test "Elm.Let.fn declaration has a type annotation" <|
\_ ->
Elm.declaration "useLetFn"
Expand Down
Loading