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

When used in switch, escape sequences (of strings) are compiled incorrectly #6060

Closed
LuKuangChen opened this issue Mar 9, 2023 · 0 comments · Fixed by #6061
Closed

When used in switch, escape sequences (of strings) are compiled incorrectly #6060

LuKuangChen opened this issue Mar 9, 2023 · 0 comments · Fixed by #6061
Milestone

Comments

@LuKuangChen
Copy link

LuKuangChen commented Mar 9, 2023

let f = s => {
  switch s {
  | "\\" => "backslash"
  | "\"" => "doublequote"
  | _ => "other"
  }
}
let s1 = "\\"
let s2 = "\""

actual output (by the latest playground as of today)

function f(s) {
  switch (s) {
    case "\\\"" :
        return "doublequote";
    case "\\\\" :
        return "backslash";
    default:
      return "other";
  }
}

var s1 = "\\";
var s2 = "\"";

I expect the two cases to be case "\"" and case "\\" instead. Not that escape sequences that are used outside the switch-case context are translated appropriately.

@cristianoc cristianoc transferred this issue from rescript-lang/syntax Mar 10, 2023
@cristianoc cristianoc added this to the v10.1 milestone Mar 10, 2023
cristianoc added a commit that referenced this issue Mar 10, 2023
Fixes #6060

The compiler's ppx was missing the same processing on patterns it performs on expressions in string constants: handles "js" string transformation. (On expressions it also handles "j" transformations).

Remove compiler error when it encounters pattern matching with processed string.

Changed compiler compilation to assume the cases in string switch are processed string.

There's still the overarching questions of whether the transformation should be performed in the parser instead.
cristianoc added a commit that referenced this issue Mar 10, 2023
Fixes #6060

The compiler's ppx was missing the same processing on patterns it performs on expressions in string constants: handles "js" string transformation. (On expressions it also handles "j" transformations).

Remove compiler error when it encounters pattern matching with processed string.

Changed compiler compilation to assume the cases in string switch are processed string.

There's still the overarching questions of whether the transformation should be performed in the parser instead.
cristianoc added a commit that referenced this issue Mar 10, 2023
Fixes #6060

The compiler's ppx was missing the same processing on patterns it performs on expressions in string constants: handles "js" string transformation. (On expressions it also handles "j" transformations).

Remove compiler error when it encounters pattern matching with processed string.

Changed compiler compilation to assume the cases in string switch are processed string.

There's still the overarching questions of whether the transformation should be performed in the parser instead.
cristianoc added a commit that referenced this issue Mar 10, 2023
Fixes #6060

The compiler's ppx was missing the same processing on patterns it performs on expressions in string constants: handles "js" string transformation. (On expressions it also handles "j" transformations).

Remove compiler error when it encounters pattern matching with processed string.

Changed compiler compilation to assume the cases in string switch are processed string.

There's still the overarching questions of whether the transformation should be performed in the parser instead.
cristianoc added a commit that referenced this issue Mar 10, 2023
* Fix issue with pattern match escape.

Fixes #6060

The compiler's ppx was missing the same processing on patterns it performs on expressions in string constants: handles "js" string transformation. (On expressions it also handles "j" transformations).

Remove compiler error when it encounters pattern matching with processed string.

Changed compiler compilation to assume the cases in string switch are processed string.

There's still the overarching questions of whether the transformation should be performed in the parser instead.

* Remove unused file.
cristianoc added a commit that referenced this issue Mar 10, 2023
Fixes #6060

The compiler's ppx was missing the same processing on patterns it performs on expressions in string constants: handles "js" string transformation. (On expressions it also handles "j" transformations).

Remove compiler error when it encounters pattern matching with processed string.

Changed compiler compilation to assume the cases in string switch are processed string.

There's still the overarching questions of whether the transformation should be performed in the parser instead.
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 a pull request may close this issue.

2 participants