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

DO NOT MERGE update Str.fromUtf8 error type #7321

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/compiler/builtins/roc/Str.roc
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,14 @@ toUtf8 : Str -> List U8
## expect Str.fromUtf8 [] == Ok ""
## expect Str.fromUtf8 [255] |> Result.isErr
## ```
fromUtf8 : List U8 -> Result Str [BadUtf8 Utf8ByteProblem U64]
fromUtf8 : List U8 -> Result Str [BadUtf8 { problem : Utf8ByteProblem, index : U64 }]
fromUtf8 = \bytes ->
result = fromUtf8Lowlevel bytes

if result.cIsOk then
Ok result.bString
else
Err (BadUtf8 result.dProblemCode result.aByteIndex)
Err (BadUtf8 { problem: result.dProblemCode, index: result.aByteIndex })

expect (Str.fromUtf8 [82, 111, 99]) == Ok "Roc"
expect (Str.fromUtf8 [224, 174, 154, 224, 174, 191]) == Ok "சி"
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/solve/tests/solve_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod solve_expr {
Str.fromUtf8
"
),
"List U8 -> Result Str [BadUtf8 Utf8ByteProblem U64]",
"List U8 -> Result Str [BadUtf8 { index : U64, problem : Utf8ByteProblem }]",
);
}

Expand Down
12 changes: 6 additions & 6 deletions crates/compiler/test_gen/src/gen_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ fn str_from_utf8_fail_invalid_start_byte() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 0x80, 99] is
Err (BadUtf8 InvalidStartByte byteIndex) ->
Err (BadUtf8 {problem: InvalidStartByte, index: byteIndex}) ->
if byteIndex == 2 then
"a"
else
Expand All @@ -712,7 +712,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 99, 0xC2] is
Err (BadUtf8 UnexpectedEndOfSequence byteIndex) ->
Err (BadUtf8 {problem: UnexpectedEndOfSequence, index: byteIndex}) ->
if byteIndex == 3 then
"a"
else
Expand All @@ -732,7 +732,7 @@ fn str_from_utf8_fail_expected_continuation() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 99, 0xC2, 0x00] is
Err (BadUtf8 ExpectedContinuation byteIndex) ->
Err (BadUtf8 {problem: ExpectedContinuation, index: byteIndex}) ->
if byteIndex == 3 then
"a"
else
Expand All @@ -752,7 +752,7 @@ fn str_from_utf8_fail_overlong_encoding() {
indoc!(
r#"
when Str.fromUtf8 [97, 0xF0, 0x80, 0x80, 0x80] is
Err (BadUtf8 OverlongEncoding byteIndex) ->
Err (BadUtf8 {problem: OverlongEncoding, index: byteIndex}) ->
if byteIndex == 1 then
"a"
else
Expand All @@ -772,7 +772,7 @@ fn str_from_utf8_fail_codepoint_too_large() {
indoc!(
r#"
when Str.fromUtf8 [97, 0xF4, 0x90, 0x80, 0x80] is
Err (BadUtf8 CodepointTooLarge byteIndex) ->
Err (BadUtf8 {problem: CodepointTooLarge, index: byteIndex}) ->
if byteIndex == 1 then
"a"
else
Expand All @@ -792,7 +792,7 @@ fn str_from_utf8_fail_surrogate_half() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 0xED, 0xA0, 0x80] is
Err (BadUtf8 EncodesSurrogateHalf byteIndex) ->
Err (BadUtf8 {problem: EncodesSurrogateHalf, index: byteIndex}) ->
if byteIndex == 2 then
"a"
else
Expand Down
12 changes: 6 additions & 6 deletions crates/compiler/test_gen/src/wasm_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ fn str_from_utf8_fail_invalid_start_byte() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 0x80, 99] is
Err (BadUtf8 InvalidStartByte byteIndex) ->
Err (BadUtf8 {problem: InvalidStartByte, index: byteIndex}) ->
if byteIndex == 2 then
"a"
else
Expand All @@ -541,7 +541,7 @@ fn str_from_utf8_fail_unexpected_end_of_sequence() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 99, 0xC2] is
Err (BadUtf8 UnexpectedEndOfSequence byteIndex) ->
Err (BadUtf8 {problem: UnexpectedEndOfSequence, index: byteIndex}) ->
if byteIndex == 3 then
"a"
else
Expand All @@ -560,7 +560,7 @@ fn str_from_utf8_fail_expected_continuation() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 99, 0xC2, 0x00] is
Err (BadUtf8 ExpectedContinuation byteIndex) ->
Err (BadUtf8 {problem: ExpectedContinuation, index: byteIndex}) ->
if byteIndex == 3 then
"a"
else
Expand All @@ -579,7 +579,7 @@ fn str_from_utf8_fail_overlong_encoding() {
indoc!(
r#"
when Str.fromUtf8 [97, 0xF0, 0x80, 0x80, 0x80] is
Err (BadUtf8 OverlongEncoding byteIndex) ->
Err (BadUtf8 {problem: OverlongEncoding, index: byteIndex}) ->
if byteIndex == 1 then
"a"
else
Expand All @@ -598,7 +598,7 @@ fn str_from_utf8_fail_codepoint_too_large() {
indoc!(
r#"
when Str.fromUtf8 [97, 0xF4, 0x90, 0x80, 0x80] is
Err (BadUtf8 CodepointTooLarge byteIndex) ->
Err (BadUtf8 {problem: CodepointTooLarge, index: byteIndex}) ->
if byteIndex == 1 then
"a"
else
Expand All @@ -617,7 +617,7 @@ fn str_from_utf8_fail_surrogate_half() {
indoc!(
r#"
when Str.fromUtf8 [97, 98, 0xED, 0xA0, 0x80] is
Err (BadUtf8 EncodesSurrogateHalf byteIndex) ->
Err (BadUtf8 {problem: EncodesSurrogateHalf, index: byteIndex}) ->
if byteIndex == 2 then
"a"
else
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions crates/compiler/test_mono/generated/encode_derived_string.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading