Skip to content

Deal with infix substitutions properly #1132

@ndmitchell

Description

@ndmitchell

Following on from #1131, when substituting a b into (`f` 1) we are likely to get ((\x_ -> a b _x 1)). The reason relates to the HSE vs GHC migration.

In the before-time, e.g. with

hlint/src/HSE/Unify.hs

Lines 53 to 60 in 0ba7612

exp (Var _ (fromNamed -> x)) = lookup x bind
exp (InfixApp s lhs (fromNamed -> x) rhs) =
(\op -> InfixApp s lhs op rhs) <$> lookupOp x
exp (LeftSection s exp (fromNamed -> x)) =
LeftSection s exp <$> lookupOp x
exp (RightSection s (fromNamed -> x) exp) =
(\op -> RightSection s op exp) <$> lookupOp x
exp _ = Nothing
, we would substitute f for the showed version of a b. And if that was an expression, then you were in trouble - but we implicitly expected no one to do that.

In the now-time, we substitute directly, and the lines at https://github.com/ndmitchell/hlint/blob/master/src/GHC/Util/Unify.hs#L73-L81 are totally useless. The GHC syntax for OpApp etc directly contain an expression, so the substitution happens even though syntactically it can't be written. And then GHC pretty prints it with the made up x_ and extra backets.

We shouldn't be deferring to GHC. Either we should ban such expansion and fail the substitution. Or we should support it and desugar it ourselves. I'm not sure.

CC @josephcsible

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions