-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port js fix for nested string prefixes
Should not generate 'prefix = "w".wobble.whatever._0.else' but rather 'prefix = "w"'
- Loading branch information
Showing
6 changed files
with
228 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...sts/snapshots/glistix_core__nix__tests__assignments__let_assert_nested_string_prefix.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/assignments.rs | ||
expression: "\ntype Wibble {\n Wibble(wibble: String)\n}\n\npub fn main() {\n let assert Wibble(wibble: \"w\" as prefix <> rest) = Wibble(\"wibble\")\n prefix <> rest\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
type Wibble { | ||
Wibble(wibble: String) | ||
} | ||
|
||
pub fn main() { | ||
let assert Wibble(wibble: "w" as prefix <> rest) = Wibble("wibble") | ||
prefix <> rest | ||
} | ||
|
||
|
||
----- COMPILED NIX | ||
let | ||
inherit (builtins.import ./../gleam.nix) strHasPrefix makeError; | ||
|
||
Wibble = wibble: { __gleamTag = "Wibble"; inherit wibble; }; | ||
|
||
main = | ||
{ }: | ||
let | ||
_pat' = (Wibble "wibble"); | ||
_assert' = | ||
if _pat'.__gleamTag != "Wibble" || !(strHasPrefix "w" _pat'.wibble) then | ||
builtins.throw | ||
(makeError | ||
"let_assert" | ||
"my/mod" | ||
7 | ||
"main" | ||
"Pattern match failed, no pattern matched the value." | ||
{ value = _pat'; }) | ||
else null; | ||
rest = builtins.seq _assert' (builtins.substring 1 (-1) _pat'.wibble); | ||
prefix = builtins.seq _assert' "w"; | ||
in | ||
builtins.seq _assert' (prefix + rest); | ||
in | ||
{ inherit main; } |
63 changes: 63 additions & 0 deletions
63
...sts/snapshots/glistix_core__nix__tests__case__deeply_nested_string_prefix_assignment.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/case.rs | ||
expression: "\ntype Wibble {\n Wibble(Wobble)\n}\ntype Wobble {\n Wobble(wabble: Wabble)\n}\ntype Wabble {\n Wabble(tuple: #(Int, String))\n}\n\npub fn main() {\n let tmp = Wibble(Wobble(Wabble(#(42, \"wibble\"))))\n case tmp {\n Wibble(Wobble(Wabble(#(_int, \"w\" as wibble <> rest)))) -> wibble <> rest\n _ -> panic\n }\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
type Wibble { | ||
Wibble(Wobble) | ||
} | ||
type Wobble { | ||
Wobble(wabble: Wabble) | ||
} | ||
type Wabble { | ||
Wabble(tuple: #(Int, String)) | ||
} | ||
|
||
pub fn main() { | ||
let tmp = Wibble(Wobble(Wabble(#(42, "wibble")))) | ||
case tmp { | ||
Wibble(Wobble(Wabble(#(_int, "w" as wibble <> rest)))) -> wibble <> rest | ||
_ -> panic | ||
} | ||
} | ||
|
||
|
||
----- COMPILED NIX | ||
let | ||
inherit (builtins.import ./../gleam.nix) strHasPrefix makeError; | ||
|
||
Wibble = x0: { __gleamTag = "Wibble"; _0 = x0; }; | ||
|
||
Wobble = wabble: { __gleamTag = "Wobble"; inherit wabble; }; | ||
|
||
Wabble = tuple: { __gleamTag = "Wabble"; inherit tuple; }; | ||
|
||
main = | ||
{ }: | ||
let | ||
tmp = Wibble (Wobble (Wabble [ 42 "wibble" ])); | ||
in | ||
if | ||
tmp.__gleamTag == "Wibble" && | ||
tmp._0.__gleamTag == "Wobble" && | ||
tmp._0.wabble.__gleamTag == "Wabble" && | ||
strHasPrefix "w" (builtins.elemAt tmp._0.wabble.tuple 1) | ||
then | ||
let | ||
rest = | ||
(builtins.substring 1 (-1) (builtins.elemAt tmp._0.wabble.tuple 1)); | ||
wibble = "w"; | ||
in | ||
wibble + rest | ||
else | ||
builtins.throw | ||
(makeError | ||
"panic" | ||
"my/mod" | ||
16 | ||
"main" | ||
"`panic` expression evaluated." | ||
{ }); | ||
in | ||
{ inherit main; } |
47 changes: 47 additions & 0 deletions
47
.../nix/tests/snapshots/glistix_core__nix__tests__case__nested_string_prefix_assignment.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/case.rs | ||
expression: "\ntype Wibble {\n Wibble(wobble: String)\n}\n\npub fn main() {\n let tmp = Wibble(wobble: \"wibble\")\n case tmp {\n Wibble(wobble: \"w\" as wibble <> rest) -> wibble <> rest\n _ -> panic\n }\n}\n" | ||
--- | ||
----- SOURCE CODE | ||
|
||
type Wibble { | ||
Wibble(wobble: String) | ||
} | ||
|
||
pub fn main() { | ||
let tmp = Wibble(wobble: "wibble") | ||
case tmp { | ||
Wibble(wobble: "w" as wibble <> rest) -> wibble <> rest | ||
_ -> panic | ||
} | ||
} | ||
|
||
|
||
----- COMPILED NIX | ||
let | ||
inherit (builtins.import ./../gleam.nix) strHasPrefix makeError; | ||
|
||
Wibble = wobble: { __gleamTag = "Wibble"; inherit wobble; }; | ||
|
||
main = | ||
{ }: | ||
let | ||
tmp = Wibble "wibble"; | ||
in | ||
if tmp.__gleamTag == "Wibble" && strHasPrefix "w" tmp.wobble then | ||
let | ||
rest = (builtins.substring 1 (-1) tmp.wobble); | ||
wibble = "w"; | ||
in | ||
wibble + rest | ||
else | ||
builtins.throw | ||
(makeError | ||
"panic" | ||
"my/mod" | ||
10 | ||
"main" | ||
"`panic` expression evaluated." | ||
{ }); | ||
in | ||
{ inherit main; } |