Skip to content

Commit bd1018c

Browse files
committed
gnd: Use != instead of !== for AS < 0.20.0 compatibility
The !== operator is not compatible with AssemblyScript versions below 0.20.0. Using != instead works correctly for null checks in both older and newer AS versions.
1 parent 533a612 commit bd1018c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

gnd/src/codegen/schema.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ impl IdFieldKind {
168168
pub fn auto_check_condition(&self) -> &'static str {
169169
match self {
170170
IdFieldKind::String => "", // N/A
171-
IdFieldKind::Bytes => "id !== null",
171+
// For Bytes we end up generating 'if (id) { .. }' Using 'id !=
172+
// null' crashes the AssemblyScript compiler 0.19.23 because id
173+
// has type 'Bytes | null' and the compiler doesn't strip the
174+
// null from the type in the body of the if
175+
IdFieldKind::Bytes => "id",
172176
IdFieldKind::Int8 => "id != i64.MIN_VALUE",
173177
}
174178
}
@@ -821,7 +825,7 @@ mod tests {
821825
assert!(IdFieldKind::Bytes.supports_auto());
822826
assert_eq!(IdFieldKind::Bytes.constructor_param_type(), "Bytes | null");
823827
assert_eq!(IdFieldKind::Bytes.constructor_default(), Some("null"));
824-
assert_eq!(IdFieldKind::Bytes.auto_check_condition(), "id !== null");
828+
assert_eq!(IdFieldKind::Bytes.auto_check_condition(), "id");
825829
}
826830

827831
#[test]
@@ -900,7 +904,7 @@ mod tests {
900904

901905
// Constructor body should conditionally set id
902906
assert!(
903-
output.contains("if (id !== null)"),
907+
output.contains("if (id)"),
904908
"Constructor should check for null"
905909
);
906910

0 commit comments

Comments
 (0)