Skip to content

Conversation

@JordanMartinez
Copy link
Contributor

Description of the change

Fixes #4012. I think the examples in the changelog entry are correct, but correct me if they're not.

This is for v0.15.x


Checklist:

  • Added a file to CHANGELOG.d for this PR (see CHANGELOG.d/README.md)
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@natefaubion
Copy link
Contributor

natefaubion commented Feb 22, 2022

The examples are not correct.

-- This is ok
case wat of Foo a -> a

-- This is ok
case wat of
  Foo a -> a

-- This is ok
case wat of Foo a ->
              a

-- This is not ok
case wat of Foo a ->
  a

There is an offside rule in case expressions, where the case branches must be indented past the pattern (just like with let). In the last example, the a is not indented past the Foo a column.

It's the same issue as let, we require the expression to be indented past the binder.

-- This is ok
let Foo a = b

-- This is ok
let Foo a =
      b

-- This is ok
let
  Foo a =
    b

-- This is not ok
let Foo a =
  b

@@ -0,0 +1,20 @@
* Remove ad-hoc same-line single-branch case statements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not single line case statements. Single line case statements are ok. It's a particular form of non-single-line case statements when there's only one branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a nit, but they are case expressions, not statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworked the entry. How about now?

@JordanMartinez JordanMartinez changed the title Drop ad-hoc same-line case statements Drop ad-hoc case expressions Feb 23, 2022
@JordanMartinez JordanMartinez changed the title Drop ad-hoc case expressions Drop support for ad-hoc case ... of expressions Feb 23, 2022
@JordanMartinez JordanMartinez mentioned this pull request Feb 27, 2022
5 tasks
@natefaubion
Copy link
Contributor

I'm personally OK with this, but the original ticket asked for a warning before removing. I think we should only remove it without a warning if the other contributors agree to it.

@JordanMartinez
Copy link
Contributor Author

I'll update this to add a warning.

| WarnDeprecatedConstraintInForeignImportSyntax
| WarnDeprecatedKindImportSyntax
| WarnDeprecatedKindExportSyntax
| WarnDeprecatedCaseOfOffsideSyntax
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no idea what to call this error, so this is what I put for now. Let me know if you have a better idea for it.

WarnDeprecatedKindExportSyntax ->
"Kind exports are deprecated and will be removed in a future release. Omit the 'kind' keyword instead."
WarnDeprecatedCaseOfOffsideSyntax ->
"An expression that is not indented past its `case ... of` branch's binder is deprecated and will be removed in a future release. Indent the expression beyond its binder, similar to how let bindings work."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems verbose, but not sure how else to explain this. Again, up for feedback here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to reference let. Maybe something like:

Dedented expressions in case branches are deprecated and will be removed in a future release. Indent the branch's expression past it's binder instead.

It's a tough concept to word succinctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning has been updated to use the above rendering. Thanks!

{% addWarning (let (a,b) = whereRange $8 in [a, b]) WarnDeprecatedCaseOfOffsideSyntax *> pure (ExprCase () (CaseOf $1 $2 $3 (pure ($5, Unconditional $6 $8)))) }
| 'case' sep(expr, ',') 'of' '\{' sep(binder1, ',') '\}' guardedCase
{ ExprCase () (CaseOf $1 $2 $3 (pure ($5, $7))) }
{% addWarning (let (a,b) = guardedRange $7 in [a, b]) WarnDeprecatedCaseOfOffsideSyntax *> pure (ExprCase () (CaseOf $1 $2 $3 (pure ($5, $7)))) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both a and b source tokens here? Or just a?

@JordanMartinez
Copy link
Contributor Author

CI error seems related to a purs bundle issue.

CST.WarnDeprecatedForeignKindSyntax -> suggest $ "data " <> CST.printTokens (drop 3 toks)
CST.WarnDeprecatedKindImportSyntax -> suggest $ CST.printTokens $ drop 1 toks
CST.WarnDeprecatedKindExportSyntax -> suggest $ CST.printTokens $ drop 1 toks
CST.WarnDeprecatedCaseOfOffsideSyntax -> suggest $ CST.printTokens toks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. This is printing a replacement suggestion. This will end up suggesting a replacement of the first and last tokens of the expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. I just dropped this by returning Nothing.

@JordanMartinez
Copy link
Contributor Author

Just wanted to note that in cc19ce8, I reverted the changes made in #4249

@JordanMartinez JordanMartinez merged commit 0177f71 into purescript:master Mar 1, 2022
@JordanMartinez JordanMartinez deleted the drop-2-case-cases branch March 1, 2022 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Remove ad-hoc handling of case formatting in the parser

3 participants