From 08179d2a653fd0b69e689c20a025bc9ad8ee0fa3 Mon Sep 17 00:00:00 2001 From: Brendan Hansknecht Date: Tue, 4 Apr 2023 17:45:23 -0700 Subject: [PATCH] make errors more correct and check for utf8 bytes --- crates/compiler/constrain/src/expr.rs | 9 +++++---- crates/compiler/mono/src/ir.rs | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/compiler/constrain/src/expr.rs b/crates/compiler/constrain/src/expr.rs index 157b9b9785..cb840fc4ab 100644 --- a/crates/compiler/constrain/src/expr.rs +++ b/crates/compiler/constrain/src/expr.rs @@ -375,14 +375,15 @@ pub fn constrain_expr( let expected_index = expected; constraints.equal_types(str_index, expected_index, Category::Str, region) } - IngestedFile(_, anno) => match &anno.typ { + IngestedFile(bytes, anno) => match &anno.typ { Type::Apply(Symbol::STR_STR, _, _) => { + if let Err(_) = std::str::from_utf8(bytes) { + todo!("cause an error for the type being wrong due to not being a utf8 string"); + } + let str_index = constraints.push_type(types, Types::STR); let expected_index = expected; constraints.equal_types(str_index, expected_index, Category::Str, region) - - // TODO: I believe we also should check to make sure they bytes are valid utf8 and bubble up an error. - // I am just not sure how the error would get bubbled up. } Type::Apply(Symbol::LIST_LIST, elem_type, _) if matches!( diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index 9299053b25..760315f9dd 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -4195,10 +4195,7 @@ pub fn with_hole<'a>( Stmt::Let(assigned, expr, list_layout, hole) } - x => todo!( - "Unsupported requested type for ingested file, give proper error: {:?}", - x - ), + _ => unreachable!("All of these cases should be dealt with earlier in the compiler, generating proper errors"), }, SingleQuote(_, _, character, _) => {