Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit 9ac003f

Browse files
authored
gf: support more dispatch on abstract types (JuliaLang/julia#31916)
This removes the restriction on defining dispatch over user-defined abstract types. The "cannot add methods to an abstract type" error is now only applicable to a couple types (`Any`, `Function`, and functions), and instead now gives a "not implemented yet" message. fixes JuliaLang/julia#14919 for 99% of cases
1 parent 8d2e50a commit 9ac003f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Test.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ function detect_ambiguities(mods...;
14311431
subambs = detect_ambiguities(f,
14321432
imported=imported, recursive=recursive, ambiguous_bottom=ambiguous_bottom)
14331433
union!(ambs, subambs)
1434-
elseif isa(f, DataType) && isdefined(f.name, :mt)
1434+
elseif isa(f, DataType) && isdefined(f.name, :mt) && f.name.mt !== Symbol.name.mt
14351435
mt = Base.MethodList(f.name.mt)
14361436
for m in mt
14371437
if m.ambig !== nothing
@@ -1445,6 +1445,24 @@ function detect_ambiguities(mods...;
14451445
end
14461446
end
14471447
end
1448+
function is_in_mods(m::Module)
1449+
while true
1450+
m in mods && return true
1451+
recursive || return false
1452+
p = parentmodule(m)
1453+
p === m && return false
1454+
m = parent
1455+
end
1456+
end
1457+
for m in Base.MethodList(Symbol.name.mt)
1458+
if m.ambig !== nothing && is_in_mods(m.module)
1459+
for m2 in m.ambig
1460+
if Base.isambiguous(m, m2.func, ambiguous_bottom=ambiguous_bottom)
1461+
push!(ambs, sortdefs(m, m2.func))
1462+
end
1463+
end
1464+
end
1465+
end
14481466
return collect(ambs)
14491467
end
14501468

0 commit comments

Comments
 (0)