From c48c53b1beec569c70816ee6dcdcb54587a223de Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Sun, 4 Aug 2024 15:08:34 +0200 Subject: [PATCH] Fix the handling of equality constraints involving concrete types --- .../FrontEnd/TypeChecking/TypeChecker.swift | 2 +- .../TypeChecking/ConditionalExtension3.hylo | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Tests/HyloTests/TestCases/TypeChecking/ConditionalExtension3.hylo diff --git a/Sources/FrontEnd/TypeChecking/TypeChecker.swift b/Sources/FrontEnd/TypeChecking/TypeChecker.swift index 404a70f35..4238c64bf 100644 --- a/Sources/FrontEnd/TypeChecking/TypeChecker.swift +++ b/Sources/FrontEnd/TypeChecking/TypeChecker.swift @@ -2207,7 +2207,7 @@ struct TypeChecker { // Rule orientation depends on ordering. var v = buildTerm(a) - var u = b.isTypeParameter ? buildTerm(b) : v.appending(.concrete(b)) + var u = buildTerm(b) if let t = TraitDecl.ID(e.decl) { v = v.substituting([.parameterType(program[t].receiver)], for: [.trait(t)]) diff --git a/Tests/HyloTests/TestCases/TypeChecking/ConditionalExtension3.hylo b/Tests/HyloTests/TestCases/TypeChecking/ConditionalExtension3.hylo new file mode 100644 index 000000000..681e37fe6 --- /dev/null +++ b/Tests/HyloTests/TestCases/TypeChecking/ConditionalExtension3.hylo @@ -0,0 +1,20 @@ +//- typeCheck expecting: .failure + +type Box { + public var contents: Contents + public memberwise init +} + +extension Box where Contents == Int { + public fun contains_zero() -> Bool { + contents == 0 + } +} + +public fun main() { + let b0 = Box(contents: true) + _ = b0.contains_zero() //! diagnostic reference to 'contains_zero' requires that 'Bool' be equal to 'Int' + + let b1 = Box(contents: 1) + _ = b1.contains_zero() +}