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 introspection macros for getproperty #35895

Closed
wants to merge 1 commit into from

Conversation

Liozou
Copy link
Member

@Liozou Liozou commented May 15, 2020

Non-@code_ introspection macros currently fail on calls to getproperty with the dot syntax. The reason is that @which should not answer the same thing depending on whether it's a call to getproperty with a module or not, i.e. the two following behaviors are expected:

julia> @which Base.nothing
Core

julia> x = LinearAlgebra.lu(rand(Int, 3, 3));

julia> @which x.factors
getproperty(F::LU{T,var"#s825"} where var"#s825"<:(StridedArray{T, 2} where T), d::Symbol) where T in LinearAlgebra at /home/liozou/julia/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/lu.jl:305

This is something I overlooked in #35522. And currently the second case fails:

julia> @which x.factors
ERROR: expected tuple type
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] to_tuple_type(::Any) at ./reflection.jl:764
 [3] which(::Any, ::Any) at ./reflection.jl:1133
 [4] top-level scope at /home/liozou/julia/usr/share/julia/stdlib/v1.6/InteractiveUtils/src/macros.jl:72

This PR fixes that. It unfortunately breaks a test that I had intentionally put in #35522. The reasoning was that the two different calls with the dot syntax were ambiguous, so we have to error in the latter case. But actually the two calls are not ambiguous: we simply have to check whether the left-hand side of the dot is a module or not, which cannot be done at macro expansion but can certainly be done runtime.

Anyway, bottom line is:

  • @which now differentiates between SomeModule.x and foo.bar (where foo is not a module) and now works in both cases (instead of only the first)
  • @less, @edit, @functionloc don't fail anymore on calls to getproperty with the dot syntax.

@Liozou
Copy link
Member Author

Liozou commented Jun 13, 2020

On second thought, I don't know if that is the best way to go. The part with @with seems unambiguous, but for the other macros it might still be better to error because I don't think someone typing @edit Base.isabstracttype (for example) wants to see the definition of getproperty. I'm leaving this open to discussion for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants