From 3605008fce3c2e7a4e1fbdf4b37f03c6e61854e5 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 1 Dec 2022 11:41:42 -0600 Subject: [PATCH] Update tests to check eq unbound float is resolved to dec --- crates/compiler/solve/tests/solve_expr.rs | 17 +++++++++++++++++ crates/compiler/types/src/subs.rs | 2 +- crates/reporting/tests/test_reporting.rs | 8 ++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/compiler/solve/tests/solve_expr.rs b/crates/compiler/solve/tests/solve_expr.rs index 262cbb8b94..6a97279a6d 100644 --- a/crates/compiler/solve/tests/solve_expr.rs +++ b/crates/compiler/solve/tests/solve_expr.rs @@ -8414,4 +8414,21 @@ mod solve_expr { "[Ok a]* -> a", ); } + + #[test] + fn resolve_eq_for_float_forces_dec() { + infer_queries!( + indoc!( + r#" + app "test" provides [main] to "./platform" + + n : Num * + + main = n == 1. + # ^ + "# + ), + @"n : Dec" + ); + } } diff --git a/crates/compiler/types/src/subs.rs b/crates/compiler/types/src/subs.rs index 9492434e71..4b189c0b26 100644 --- a/crates/compiler/types/src/subs.rs +++ b/crates/compiler/types/src/subs.rs @@ -1588,7 +1588,7 @@ fn float_type( num_binary64, AliasVariables::default(), Variable::EMPTY_TAG_UNION, - AliasKind::Structural, + AliasKind::Opaque, ) }); } diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index b709bfaa5f..9322aa86bb 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -12594,7 +12594,7 @@ I recommend using camelCase. It's the standard style in Roc code! n : Num * - main = n == 1. + main = n == 1f64 "# ), @r###" @@ -12602,12 +12602,12 @@ I recommend using camelCase. It's the standard style in Roc code! This expression has a type that does not implement the abilities it's expected to: - 5│ main = n == 1. - ^^ + 5│ main = n == 1f64 + ^^^^ I can't generate an implementation of the `Eq` ability for - FloatingPoint * + FloatingPoint ? Note: I can't derive `Bool.isEq` for floating-point types. That's because Roc's floating-point numbers cannot be compared for total