Skip to content

Redefinition of a constant should be an error, rather than a warning #1389

@pao

Description

@pao

[Originally posted on -dev by Fermat 618: https://groups.google.com/d/topic/julia-dev/MOt74gNrc9E/discussion]

When I assign a lambda to a function,

julia> f(x) = x + 2

julia> f = (x) -> x + 20
Warning: redefinition of constant f ignored.
#<function>

julia> f(3)
5

I find neither an Error is raised nor the assignment take effect.

It is very dangerous to ignore an error. A program that returns a wrong
answer is much more worse than a program that fails.

When I write something, I expected it to take effect. If it do not, I
expect an error. A warning is reasonable when someone write

     if (a = b) { xxx; }

in C. Even though if (a == b) is likely what one want, one can still
ignore the warning when he/she is sure if (a = b) is wanted. But this
is definitely not the case.

In my opinion, a well designed programming language should give as less
[warnings] as possible.

Metadata

Metadata

Assignees

Labels

needs decisionA decision on this change is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions