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

Error when showing method list #49382

Closed
fredrikekre opened this issue Apr 17, 2023 · 0 comments · Fixed by #52354
Closed

Error when showing method list #49382

fredrikekre opened this issue Apr 17, 2023 · 0 comments · Fixed by #52354
Labels
bug Indicates an unexpected problem or unintended behavior display and printing Aesthetics and correctness of printed representations of objects. regression Regression in behavior compared to a previous version regression 1.9 Regression in the 1.9 release

Comments

@fredrikekre
Copy link
Member

Reproducer:

julia> module A
           abstract type B end
       end;

julia> (::Type{A.B})() = 1;

julia> methods(A.B)
# 1 method for type constructor:Error showing value of type Base.MethodList:
ERROR: "B" is not defined in module Main
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] which
    @ ./reflection.jl:1643 [inlined]
  [3] show_method_table(io::IOContext{Base.TTY}, ms::Base.MethodList, max::Int64, header::Bool)
    @ Base ./methodshow.jl:303
  [4] show_method_table
    @ ./methodshow.jl:289 [inlined]
  [5] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, ms::Base.MethodList)
    @ Base ./methodshow.jl:349

Note that it does not happen if (::Type{A.B})() = 1 is inside module A ... end.

@KristofferC KristofferC added bug Indicates an unexpected problem or unintended behavior display and printing Aesthetics and correctness of printed representations of objects. labels Apr 17, 2023
@ararslan ararslan added regression Regression in behavior compared to a previous version regression 1.9 Regression in the 1.9 release labels Nov 7, 2023
ararslan added a commit that referenced this issue Nov 30, 2023
When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

To fix this, we can look through the available methods and choose the
first in which the type is defined in the method's module, falling back
to the method table's module otherwise.

Fixes #49382
Fixes #49403
Fixes #52043
ararslan added a commit that referenced this issue Dec 21, 2023
When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
ararslan added a commit that referenced this issue Dec 22, 2023
)

When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
ararslan added a commit that referenced this issue Dec 22, 2023
)

When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
(cherry picked from commit 40bc64c)
KristofferC pushed a commit that referenced this issue Dec 23, 2023
)

When a type is defined in one module but its methods are defined
elsewhere, `show_method_table` errors due to an incorrect lookup of the
defining module used to determine colors for printing. In particular,
the code had been assuming that the type is defined in the module in
which its constructor's first method (in the sense of
`first(methods())`) is defined, which isn't always true.

The color used for printing the module name needs to be determined on a
per-method basis and can't be correctly done based on the method table's
module. For each method, we attempt to derive the module for the method
table to which the method was added, then determine whether it's the
same as the defining module for the method.

Fixes #49382
Fixes #49403
Fixes #52043

Co-Authored-By: Jameson Nash <[email protected]>
(cherry picked from commit 40bc64c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior display and printing Aesthetics and correctness of printed representations of objects. regression Regression in behavior compared to a previous version regression 1.9 Regression in the 1.9 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants