BrowserREPL-button-tip-on BrowserREPL-button-tip-off

EditButtonTip 2019-08-04

class X::Redeclaration

Compilation error due to declaring an already declared symbol

class X::Redeclaration does X::Comp { }
Code

Thrown when a symbol (variable, routine, type, parameter, ...) is redeclared. Note that redeclarations are generally fine in an inner scope, but if the redeclaration appears in the same scope as the original declaration, it usually indicates an error and is treated as one.

Examples

my $x; my $x;
Code

dies with

===SORRY!===
Redeclaration of symbol $x
Code

It works with routines too:

sub f() { }
sub f() { }
Code

dies with

===SORRY!===
Redeclaration of routine f
Code

But those are fine

my $x;
sub f() {
    my $x;          # not a redeclaration,
                    # because it's in an inner scope
    sub f() { };    # same
}
Code

Methods§

method symbol§

Returns the name of the symbol that was redeclared.

method what§

Returns the kind of symbol that was redeclared. Usually symbol, but can also be routine, type etc.

method postfix§

Returns a string that is attached to the end of the error message. It usually explains the particular problem in more detail, or suggests way to fix the problem.