Julia: feature request: implement error for overloading "final" methods

Created on 1 Mar 2019  Â·  3Comments  Â·  Source: JuliaLang/julia

From a (trolly) discourse post (https://discourse.julialang.org/t/module-with-one-function-of-same-name-as-the-module/21305/3):

module a
    _a() = println("Hello there!")
    function Base.getproperty(m::Module, x::Symbol)
        if m === a && x === :a
            return getfield(m, :_a)
        else
            return getfield(m, x)
        end
    end
end

Executing some stuff in the REPL

julia> a.a
Main.a

julia> b = a.a
_a (generic function with 1 method)

It seems odd to me that a.a returns Main.a instead of _a. Perhaps this is the interpreter that is running and take a fast path for getproperty and type piracy like this is not supported.

Most helpful comment

:+1: Yes, there are two nice features we could add here: (1) Sealed functions, where you can't add any new methods, and (2) sealed methods, where you can't replace it or add any methods more specific than it.

All 3 comments

@vtjnash, can you explain what the new issue title means?

Probably that this type of type piracy should just error. Ie this method should be considered closed.

:+1: Yes, there are two nice features we could add here: (1) Sealed functions, where you can't add any new methods, and (2) sealed methods, where you can't replace it or add any methods more specific than it.

Was this page helpful?
0 / 5 - 0 ratings