Skip to content
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

Generated scala code may improperly group list patterns #1141

Open
edwardpeters opened this issue Feb 8, 2024 · 1 comment
Open

Generated scala code may improperly group list patterns #1141

edwardpeters opened this issue Feb 8, 2024 · 1 comment
Labels
task Task level project item

Comments

@edwardpeters
Copy link

Describe the bug
If an elm pattern match statement has nested list expressions, the generated scala code may improperly group them.

To Reproduce
Start with the following elm source code:

describe : List (List Int) -> String
describe ll = case ll of
    (_ :: _) :: _ -> "This starts with a list of at least one element"
    _ :: _ :: _ -> "This contains at least two sublists"
    _ -> "Other"

listDescribeTest1 : Int -> String
listDescribeTest1 x = describe [[x]]

listDescribeTest2 : Int -> String
listDescribeTest2 x = describe [[], [x]]

describe operates on lists of lists. The first arm of the match statement should match any list which has a first element which itself has a first element. The second arm should then catch lists of at least two elements.

This is the behavior in both native elm and the morphir-elm interpreter, which show each of the first two arms being matched by listDescribeTest1 and listDescribeTest2 respectively.

However, if morphir-elm gen is called, the following scala code is produced for the describe function:

def describe(
    ll: morphir.sdk.List.List[morphir.sdk.List.List[morphir.sdk.Basics.Int]]
  ): morphir.sdk.String.String =
    ll match {
      case _ :: _ :: _ => 
        "This starts with a list of at least one element"
      case _ :: _ :: _ => 
        "This contains at least two sublists"
      case _ => 
        "Other"
    }

Here, the grouping information has been lost and the first arm completely shadows the second. (In this example it will at least result in a scala compiler warning, but in others - such as if the second case were omitted - it would produce apparently legal scala code with the incorrect behavior.)

Expected behavior
Generated scala patterns should be grouped the same way as the elm source code.

Desktop (please complete the following information):

  • OS: OSX
  • Version: 2.87.6
@edwardpeters edwardpeters added the task Task level project item label Feb 8, 2024
@edwardpeters
Copy link
Author

@AttilaMihaly I revisited this and it seems to no longer be happening - can you confirm that this bug has been closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Task level project item
Projects
None yet
Development

No branches or pull requests

1 participant