Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic of @import #168

Open
wants to merge 1 commit into
base: md_fix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/models/ModelInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,7 @@ function typecheck_instance(

overload_errormsg =
"the types for this model declaration do not permit Julia overloading to distinguish between GAT overloads"

for (decl, resolver) in theory.resolvers
if nameof(decl) ∈ ext_functions
continue
end
for (_, x) in allmethods(resolver)
if getvalue(theory[x]) isa AlgStruct
continue
Expand Down Expand Up @@ -455,6 +451,7 @@ function typecheck_instance(
end

for (sig, (decl, method)) in undefined_signatures
nameof(decl) ∈ ext_functions && continue # assume it has been impl'd already
judgment = getvalue(theory[method])
if judgment isa AlgTermConstructor
error("Failed to implement $decl: $(toexpr(sig))")
Expand Down
26 changes: 26 additions & 0 deletions test/models/ModelInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,30 @@ end
munit() = 0
end

# Test scenario where we @import a method but then extend it
############################################################
@theory T1 begin
X::TYPE;
h(a::X)::X
end

@theory T2<:T1 begin
Y::TYPE;
h(b::Y)::Y
end

@instance T1{Int} begin
h(a::Int) = 1
end

@instance T2{Int,Bool} begin
@import X, h
h(b::Bool) = false
end

@test h(2) == 1

@test h(false) == false


end # module
Loading