Skip to content

Commit

Permalink
Merge pull request #1549 from hylo-lang/equality-to-concrete-type
Browse files Browse the repository at this point in the history
Fix the handling of equality constraints involving concrete types
  • Loading branch information
kyouko-taiga authored Aug 4, 2024
2 parents 5fb6cfe + 9a94164 commit 16c9525
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Sources/FrontEnd/TypeChecking/TypeChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModuleDecl.ID> {
if let result = cache.read(\.imports[u]) {
return result
}

// The core library and the containing module are always implicitly imported.
var result = Set<ModuleDecl.ID>()
result.insert(ModuleDecl.ID(program[u].scope)!)
var result: Set<ModuleDecl.ID> = [ModuleDecl.ID(program[u].scope)!]
if let m = program.ast.coreLibrary {
result.insert(m)
}
Expand Down Expand Up @@ -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)])
Expand Down
2 changes: 1 addition & 1 deletion Sources/IR/Emitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
20 changes: 20 additions & 0 deletions Tests/HyloTests/TestCases/TypeChecking/ConditionalExtension3.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//- typeCheck expecting: .failure

type Box<Contents: Regular> {
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()
}

0 comments on commit 16c9525

Please sign in to comment.