Skip to content

Unexpected behavior when assigning to function #18877

@mfalt

Description

@mfalt

I am not sure if this is a bug, but the following certainly creates some unexpected behavior (unexpected error message at least) and debugging headache where the assignment to length was supposed to be a test length(b)==2.

function f(a, b)
    N = length(a)
    length(b) = 2
    return N
end
f((1,2),(3,4))

which results in

ERROR: UndefVarError: length not defined
 in f(::Tuple{Int64,Int64}, ::Tuple{Int64,Int64}) at ./REPL[3]:2

especially when the assignment is not even reachable

function g(a, b)
    return length(a)
    length(b) = 2
end
g((1,2),(3,4))
ERROR: UndefVarError: length not defined
 in g(::Tuple{Int64,Int64}, ::Tuple{Int64,Int64}) at ./REPL[6]:2

Notice that the error occurs at the length(a) call, not in the assignment statements.

Running Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestGood for Hacktoberfest participantsdocsThis change adds or pertains to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions