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

fix(compiler): Fix incorrect char well-formedness error #837

Merged
merged 1 commit into from
Sep 1, 2021
Merged
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
2 changes: 1 addition & 1 deletion compiler/src/parsing/well_formedness.re
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let malformed_characters = (errs, super) => {
let iter_expr = (self, {pexp_desc: desc, pexp_loc: loc} as e) => {
switch (desc) {
| PExpConstant(PConstChar(c)) =>
if (Utf8.countInString(c) != 1) {
if (List.length(Utf8.decodeUtf8String(c)) != 1) {
errs := [IllegalCharacterLiteral(c, loc), ...errs^];
}
| _ => ()
Expand Down
50 changes: 50 additions & 0 deletions compiler/test/__snapshots__/chars.27fb7f30.0.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
chars › char8
(module
(type $none_=>_none (func))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(import \"_grainEnv\" \"mem\" (memory $0 0))
(import \"_grainEnv\" \"relocBase\" (global $import__grainEnv_0_relocBase_0 i32))
(import \"GRAIN$MODULE$runtime/gc\" \"GRAIN$EXPORT$malloc\" (global $import_GRAIN$MODULE$runtime/gc_0_GRAIN$EXPORT$malloc_0 (mut i32)))
(import \"GRAIN$MODULE$runtime/gc\" \"malloc\" (func $import_GRAIN$MODULE$runtime/gc_0_malloc_0 (param i32 i32) (result i32)))
(global $global_1 i32 (i32.const 0))
(export \"memory\" (memory $0))
(export \"_gmain\" (func $_gmain))
(export \"_start\" (func $_start))
(export \"GRAIN$TABLE_SIZE\" (global $global_1))
(func $_gmain (; has Stack IR ;) (result i32)
(local $0 i32)
(tuple.extract 0
(tuple.make
(block (result i32)
(i32.store
(local.tee $0
(tuple.extract 0
(tuple.make
(call $import_GRAIN$MODULE$runtime/gc_0_malloc_0
(global.get $import_GRAIN$MODULE$runtime/gc_0_GRAIN$EXPORT$malloc_0)
(i32.const 8)
)
(i32.const 0)
)
)
)
(i32.const 2)
)
(i32.store offset=4
(local.get $0)
(i32.const 11050210)
)
(local.get $0)
)
(local.get $0)
)
)
)
(func $_start (; has Stack IR ;)
(drop
(call $_gmain)
)
)
;; custom section \"cmi\", size 237
)
1 change: 1 addition & 0 deletions compiler/test/suites/chars.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("chars", ({test}) => {
assertSnapshot("char5", "'\\u{41}'");
assertSnapshot("char6", "'💯'");
assertSnapshot("char7", "'\\u{1F33E}'");
assertSnapshot("char8", "'\\u2728'");
assertRun("char_eq1", "print('🌾' == '🌾')", "true\n");
assertRun("char_eq2", "print('🌾' == '💯')", "false\n");
assertRun(
Expand Down