Skip to content

Commit 49028d3

Browse files
dillonkearnsclaude
andcommitted
Skip generic-return synthesis when apply has zero args.
`apply fn []` with an unknown fn type should still be unknown (the result is the fn itself, whose type we still don't know), rather than gaining a synthesized return type out of thin air. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c85a5f7 commit 49028d3

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

src/Internal/Compiler.elm

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,22 +1581,27 @@ applyType index annotation args =
15811581
-- Elm.unwrapper can't derive an annotation for its lambda).
15821582
-- Synthesize a fresh generic return type so downstream
15831583
-- inference can still flow through the application.
1584-
if Index.typecheck index then
1585-
case mergeArgInferences args [] Dict.empty of
1586-
Ok mergedArgs ->
1587-
Ok
1588-
{ type_ =
1589-
Annotation.GenericType
1590-
(Index.protectTypeName "result" index)
1591-
, inferences = mergedArgs.inferences
1592-
, aliases = emptyAliases
1593-
}
1584+
--
1585+
-- Only synthesize when args is non-empty; `apply fn []`
1586+
-- with an unknown fn is still "unknown" (the result is
1587+
-- the fn itself, whose type we still don't know).
1588+
case ( Index.typecheck index, args ) of
1589+
( True, _ :: _ ) ->
1590+
case mergeArgInferences args [] Dict.empty of
1591+
Ok mergedArgs ->
1592+
Ok
1593+
{ type_ =
1594+
Annotation.GenericType
1595+
(Index.protectTypeName "result" index)
1596+
, inferences = mergedArgs.inferences
1597+
, aliases = emptyAliases
1598+
}
15941599

1595-
Err _ ->
1596-
Err []
1600+
Err _ ->
1601+
Err []
15971602

1598-
else
1599-
Err []
1603+
_ ->
1604+
Err []
16001605

16011606
Ok fnAnnotation ->
16021607
if Index.typecheck index then

0 commit comments

Comments
 (0)