8000 Variable names clashing across guard clauses · Issue #4357 · purescript/purescript · GitHub
[go: up one dir, main page]

Skip to content
Variable names clashing across guard clauses #4357
@nwolverson

Description

@nwolverson

Description

This is a regression apparently introduced in #4293.

A case statement containing guard clauses with pattern guards which bind the same variable result in an error when building with 0.15.3 but not 1887bcf (just before that PR was merged).

To Reproduce

data Foo = Foo Int | Bar Int

g :: Foo -> Int
g  =
  case _ of
    a
        | Bar z <- a
        -> z
        | Foo z <- a
        -> z
        | otherwise
        -> 42

Results in the following error:

Error found:
in module Main
at src/Main.purs:15:12 - 15:13 (line 15, column 12 - line 15, column 13)

  Value z is undefined.

while inferring the type of z
in value declaration g

After renaming the z in the 1st guard clause, the error disappears.

Expected behavior

No error - as in previous compiler versions.

Variables bound in guard clauses are only in scope in the corresponding expression, and there is no conflict between different guard clauses.

Additional context

Add any other context about the problem here.

PureScript version

0.15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0