⭐️ A friendly language for building type-safe, scalable systems!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Do not add redundant checks for nil values

authored by giacomocavalieri.me and committed by

Louis Pilfold 7e80a987 a5cb46c8

+29 -7
+1 -6
compiler-core/src/javascript/decision.rs
··· 384 384 // We never generate runtime checks for tuples, so we skip 385 385 // those altogether here. 386 386 RuntimeCheck::Tuple { .. } => None, 387 + RuntimeCheck::Variant { .. } if variable.type_.is_nil() => None, 387 388 _ => self 388 389 .variables 389 390 .runtime_check(variable, check, CheckNegation::Negated) ··· 879 880 (_, CheckNegation::NotNegated) => docvec!["!", value, ".isOk()"], 880 881 (_, CheckNegation::Negated) => docvec![value, ".isOk()"], 881 882 } 882 - } 883 - 884 - // Checking that a value typed as `Nil` is not `Nil` is always going 885 - // fail. 886 - RuntimeCheck::Variant { .. } if variable.type_.is_nil() && negation.is_negated() => { 887 - "false".to_doc() 888 883 } 889 884 890 885 RuntimeCheck::Variant { match_, .. } => {
+11
compiler-core/src/javascript/tests/assert.rs
··· 162 162 "# 163 163 ); 164 164 } 165 + 166 + #[test] 167 + fn assert_nil_always_throws() { 168 + assert_js!( 169 + r#" 170 + pub fn go(x: Nil) { 171 + let assert Nil = x 172 + } 173 + "# 174 + ); 175 + }
+16
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_nil_always_throws.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/assert.rs 3 + expression: "\npub fn go(x: Nil) {\n let assert Nil = x\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn go(x: Nil) { 8 + let assert Nil = x 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + export function go(x) { 14 + 15 + return x; 16 + }
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__blocks__let_assert_message_no_lifted.snap
··· 27 27 28 28 export function main() { 29 29 let $ = side_effects(new Ok(10)); 30 - if ($.isOk() || false) { 30 + if ($.isOk()) { 31 31 throw makeError( 32 32 "let_assert", 33 33 "my/mod",