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

Improve MultipleDefinitionsError when combining methods&variables #12

Merged
merged 3 commits into from
Oct 21, 2024
Merged
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
13 changes: 11 additions & 2 deletions src/Errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ 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

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
Loading