diff --git a/Sources/FrontEnd/TypeChecking/TypeChecker.swift b/Sources/FrontEnd/TypeChecking/TypeChecker.swift index 2627dc38d..4238c64bf 100644 --- a/Sources/FrontEnd/TypeChecking/TypeChecker.swift +++ b/Sources/FrontEnd/TypeChecking/TypeChecker.swift @@ -1355,14 +1355,16 @@ struct TypeChecker { } /// Returns the modules visible as imports in `u`. + /// + /// The returned set contains the modules declared as explicit imports at the top of `u` along + /// with the standard library and the module containing `u`. private mutating func imports(exposedTo u: TranslationUnit.ID) -> Set { if let result = cache.read(\.imports[u]) { return result } // The core library and the containing module are always implicitly imported. - var result = Set() - result.insert(ModuleDecl.ID(program[u].scope)!) + var result: Set = [ModuleDecl.ID(program[u].scope)!] if let m = program.ast.coreLibrary { result.insert(m) } @@ -2205,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/Sources/IR/Emitter.swift b/Sources/IR/Emitter.swift index 773f5753c..bf6850869 100644 --- a/Sources/IR/Emitter.swift +++ b/Sources/IR/Emitter.swift @@ -2516,7 +2516,7 @@ struct Emitter { private func unexpectedCoercion( from lhs: AnyType, to rhs: AnyType, file: StaticString = #file, line: UInt = #line ) -> Never { - fatalError("unexpected coercion from '\(lhs)' to \(rhs)", file: file, line: line) + fatalError("unexpected coercion from '\(lhs)' to '\(rhs)'", file: file, line: line) } /// Inserts the IR for converting `foreign` to a value of type `ir`. 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() +}