Skip to content

Inconsistent behavior when extending an operator without first importing it. #2071

@GunnarFarneback

Description

@GunnarFarneback

I know that I need to explicitly import operators from Base if I want to extend them but it is confusing that if I fail to do so, it can either give a helpful error or silently make a new operator depending on whether I've previously used that particular operator.

julia> "a"*2
no method *(ASCIIString,Int64)

julia> *(a::String, b::Int) = "$a$b"
error in method definition: function Base.* must be explicitly imported to be extended

julia> +(a::String, b::Int) = "$a$b"

julia> +
Methods for generic function +
+(String,Int64) at none:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions