E50050: Variable/Constant duplicated
What went wrong
A variable with this name is already declared in the current scope. Each variable name must be unique within its scope.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 79 (What is the assign-if-unset operator :=? in EK9?)
Operator distinction
- '<-' (declaration): creates NEW variable with inferred type
- ':=' (assignment): assigns to EXISTING variable
- ':=?' (guarded): assigns only if UNSET
How to fix it
- If updating existing variable: use ':=' instead of '<-'
- If creating new variable: use a different name
- Check for typos that accidentally match existing variable
Common causes
- Using '<-' when ':=' was intended (update vs create)
- Copy-paste error duplicating declaration
- Variable name collision with earlier declaration
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E50050: Variable/Constant duplicated
#!ek9 defines module error.e50050.bad defines function demo() <- rtn as Integer? total <- 42 total <- 100 rtn: total
Fixed: Assign the existing variable with :=
#!ek9 defines module error.e50050.good defines function demo() <- rtn as Integer? total <- 42 total := total + 100 rtn: total
Fixed: Or give the second value its own name
#!ek9 defines module error.e50050.good.new.name defines function demo() <- rtn as Integer? first <- 42 second <- 100 rtn: first + second
Questions and answers
These Q&A entries show E50050 and its fix:
- Q79: What is the assign-if-unset operator :=? in EK9?
- Q879: What is the difference between <-, :=, and :=: in EK9?
- Q881: I keep getting errors mixing up <- and := in EK9. What is the rule?
- Q895: What is the difference between <- and := in EK9?
- Q1980: What do <-, :=? and := each do in the head of an if, switch, for, while or try?
- Q1983: Does a guard in a while or do/while head run on every iteration?