Skip to content

refactor: use existing IllegalVariableInPatternAlternative message #14805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

ckipp01
Copy link
Member

@ckipp01 ckipp01 commented Mar 29, 2022

We have a IllegalVariableInPatternAlternative message that already
exists and was used in Desugar, but not in the more common place
people will see it in Typer. This just changes the message to align
with the one that people are used to seeing, but also adds in the
explain since we're re-using the existing message.

Example before

scala> Option((1, 2)) match
     |   case (1, n) | (n, 1) => "got a one!"
     |
-- Error: ----------------------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |           ^
  |           Illegal variable n in pattern alternative
-- Error: ----------------------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |                 ^
  |                 Illegal variable n in pattern alternative
2 errors found

Example after

scala> Option((1, 2)) match
     |   case (1, n) | (n, 1) => "got a one!"
     |
-- [E024] Syntax Error: --------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |           ^
  |           Illegal variable n in pattern alternative
  |
  | longer explanation available when compiling with `-explain`
-- [E024] Syntax Error: --------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |                 ^
  |                 Illegal variable n in pattern alternative
  |
  | longer explanation available when compiling with `-explain`
2 errors found

We have a `IllegalVariableInPatternAlternative` message that already
exists and was used in `Desugar`, but not in the more common place
people will see it in `Typer`. This just changes the message to align
with the one that people are used to seeing, but also adds in the
`explain` since we're re-using the existing message.

_Example before_
```
scala> Option((1, 2)) match
     |   case (1, n) | (n, 1) => "got a one!"
     |
-- Error: ----------------------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |           ^
  |           Illegal variable n in pattern alternative
-- Error: ----------------------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |                 ^
  |                 Illegal variable n in pattern alternative
2 errors found
```

_Example after_

```
scala> Option((1, 2)) match
     |   case (1, n) | (n, 1) => "got a one!"
     |
-- [E024] Syntax Error: --------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |           ^
  |           Illegal variable n in pattern alternative
  |
  | longer explanation available when compiling with `-explain`
-- [E024] Syntax Error: --------------------------------------------------------
2 |  case (1, n) | (n, 1) => "got a one!"
  |                 ^
  |                 Illegal variable n in pattern alternative
  |
  | longer explanation available when compiling with `-explain`
2 errors found
```
@smarter smarter enabled auto-merge March 29, 2022 12:12
@smarter smarter merged commit 15fccde into scala:main Mar 29, 2022
@ckipp01 ckipp01 deleted the illegalStuff branch March 29, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants