Skip to content

Commit

Permalink
Merge pull request #966 from hylo-lang/name-lookup-alias
Browse files Browse the repository at this point in the history
Fix name lookup through type aliases
  • Loading branch information
kyouko-taiga authored Sep 7, 2023
2 parents 55a6769 + b9952b1 commit 0f187d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Sources/FrontEnd/TypeChecking/TypeChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,8 @@ struct TypeChecker {
return lookup(stem, memberOf: t.bareType, exposedTo: scopeOfUse)
case let t as GenericTypeParameterType:
return lookup(stem, memberOf: t, exposedTo: scopeOfUse)
case let t as TypeAliasType:
return lookup(stem, memberOf: t, exposedTo: scopeOfUse)
default:
break
}
Expand All @@ -2414,8 +2416,6 @@ struct TypeChecker {
matches = names(introducedIn: t.decl)[stem, default: []]
case let t as TraitType:
matches = names(introducedIn: t.decl)[stem, default: []]
case let t as TypeAliasType:
matches = names(introducedIn: t.decl)[stem, default: []]
default:
matches = []
}
Expand Down Expand Up @@ -2461,6 +2461,19 @@ struct TypeChecker {
return matches
}

/// Returns the declarations that introduce a name with given `stem` as member of `nominalScope`
/// and are exposed to `scopeOfUse`.
private mutating func lookup(
_ stem: String, memberOf nominalScope: TypeAliasType,
exposedTo scopeOfUse: AnyScopeID
) -> Set<AnyDeclID> {
if let d = names(introducedIn: nominalScope.decl)[stem] {
return d
} else {
return lookup(stem, memberOf: nominalScope.aliasee.value, exposedTo: scopeOfUse)
}
}

/// Returns the declarations that introduce a name with given `stem` in extensions of
/// `nominalScope` and are exposed to `scopeOfUse`.
private mutating func lookup(
Expand Down
12 changes: 12 additions & 0 deletions Tests/HyloTests/TestCases/TypeChecking/NameLookupWithAlias.hylo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//- typeCheck expecting: success

public type X {
public let a: Int = 32
}

typealias Y = X

fun f(x: X, y: Y) -> Int {
let c = x.a
return c + y.a
}

0 comments on commit 0f187d1

Please sign in to comment.