Skip to content

Commit

Permalink
Improve MultipleDefinitionsError when combining methods and plain var…
Browse files Browse the repository at this point in the history
…iables
  • Loading branch information
fonsp committed Oct 21, 2024
1 parent b998a9c commit c1c2a78
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/Errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ end

function MultipleDefinitionsError(topology::NotebookTopology, cell::AbstractCell, all_definers)
competitors = setdiff(all_definers, [cell])
defs(c) = topology.nodes[c].funcdefs_without_signatures topology.nodes[c].definitions

dd(c) = topology.nodes[c].definitions
df(c) = topology.nodes[c].funcdefs_with_signatures
ddf(c) = topology.nodes[c].definitions topology.nodes[c].funcdefs_without_signatures

@info "huh" dd(cell) df(cell)
MultipleDefinitionsError(
union((defs(cell) defs(c) for c in competitors)...)
union!(
Set{Symbol}(),
(dd(cell) ddf(c) for c in competitors)...,
(ddf(cell) dd(c) for c in competitors)...,
((funcdef.name.joined for funcdef in df(cell) df(c)) for c in competitors)...,
)
)
end

Expand Down
37 changes: 34 additions & 3 deletions test/pluto integration/React.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PlutoDependencyExplorer: CyclicReferenceError, MultipleDefinitionsError

### MORE TESTS ARE IN PLUTO.jL
# The tests on the Pluto side are tests that rely more heavily on what Pluto implements on top of PlutoDependencyExplorer.
# The tests in PlutoDependencyExplorer are focus in *reactive ordering*.
# The tests in PlutoDependencyExplorer focus on *reactive ordering*.

order_to_run(notebook, id::Integer) = order_to_run(notebook, [id])
function order_to_run(notebook, idx)
Expand Down Expand Up @@ -39,7 +39,7 @@ end
@test notebook.cells[1] |> noerror
@test notebook.cells[2] |> noerror

# https://github.com/fonsp/Pluto.jl/issues/26
# https://github.com/fonsp/Pluto.jl/issues/26
setcode!(notebook.cells[1], "x = 1")
update_run!(🍭, notebook, notebook.cells[1])
setcode!(notebook.cells[2], "x")
Expand Down Expand Up @@ -376,6 +376,19 @@ end
e13=27
e14
end"""),

Cell("""
begin
ppp = 28
Base.zero(::YAY) = 28
end
"""),
Cell("""
begin
ppp = 29
Base.zero(::NOO) = 29
end
"""),
])

update_run!(🍭, notebook, notebook.cells[1:4])
Expand Down Expand Up @@ -496,7 +509,7 @@ end
update_run!(🍭, notebook, notebook.cells[20])
@test occursinerror("Multiple definitions", notebook.cells[19])
@test occursinerror("Multiple definitions", notebook.cells[20])
@test occursinerror("asdf", notebook.cells[20])
@test occursinerror("asdf", notebook.cells[19])
@test occursinerror("asdf", notebook.cells[20])
@test notebook.cells[21].errored == true
@test notebook.cells[22].errored == true
Expand Down Expand Up @@ -535,6 +548,24 @@ end
setcode!(notebook.cells[23], "@assert !any(isdefined.([@__MODULE__], [Symbol(:e,i) for i in 1:14]))")
update_run!(🍭, notebook, notebook.cells[23])
@test notebook.cells[23] |> noerror

update_run!(🍭, notebook, notebook.cells[28:29])
@test occursinerror("Multiple definitions", notebook.cells[28])
@test occursinerror("Multiple definitions", notebook.cells[29])
@test occursinerror("ppp", notebook.cells[28])
@test occursinerror("ppp", notebook.cells[29])
@test !occursinerror("zero", notebook.cells[28])
@test !occursinerror("zero", notebook.cells[29])

setcode!(notebook.cells[29], replace(notebook.cells[29].code, "NOO" => "YAY"))
update_run!(🍭, notebook, notebook.cells[29])
@test occursinerror("Multiple definitions", notebook.cells[28])
@test occursinerror("Multiple definitions", notebook.cells[29])
@test occursinerror("ppp", notebook.cells[28])
@test occursinerror("ppp", notebook.cells[29])
@test occursinerror("zero", notebook.cells[28])
@test occursinerror("zero", notebook.cells[29])


WorkspaceManager.unmake_workspace((🍭, notebook); verbose=false)

Expand Down

0 comments on commit c1c2a78

Please sign in to comment.