Skip to content

Commit f308c62

Browse files
committed
document more exception classes
1 parent 3e51487 commit f308c62

File tree

10 files changed

+312
-0
lines changed

10 files changed

+312
-0
lines changed

lib/X/Attribute/Undeclared.pod

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=begin pod
2+
3+
=title class X::Attribute::Undeclared
4+
5+
class X::Attribute::Undeclared is X::Undeclared { }
6+
7+
Thrown when code refers to an attribute that has not been declared.
8+
9+
For example the code
10+
11+
class A { method m { $!notthere } }
12+
13+
Produces the error
14+
15+
Attribute $!notthere not declared in class A
16+
17+
=head1 Methods
18+
19+
=head2 package-kind
20+
21+
Returns the kind of package the attribute was used in (for example C<class>,
22+
C<grammar>)
23+
24+
=head2 package-name
25+
26+
Returns the name of the package in which the offensive attribute reference
27+
was performed.
28+
29+
=end pod

lib/X/Parameter/Default.pod

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=begin pod
2+
3+
=TITLE class X::Parameter::Default
4+
5+
class X::Parameter::Default does X::Comp { }
6+
7+
Compile-time error thrown when a parameter in a signature has default value,
8+
but isn't allowed to have one. That is the case with slurpy parameters
9+
(because a slurpy always binds successfully, even to zero arguments)
10+
and with mandatory parameters.
11+
12+
Example:
13+
14+
sub f($x! = 3) { }
15+
16+
Produces
17+
18+
===SORRY!===
19+
Cannot put default on required parameter $x
20+
21+
And
22+
23+
sub f(*@ = 3) { }
24+
25+
produces
26+
27+
Cannot put default on anonymous slurpy parameter
28+
29+
=head1 Methods
30+
31+
=head2 how
32+
33+
Returns a string describing how the parameter is qualified that makes
34+
it disallow default values, for example C<"slurpy"> or C<"mandatory">.
35+
36+
=head2 parameter
37+
38+
Returns the parameter name
39+
40+
=end pod
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=begin pod
2+
3+
=TITLE X::Parameter::MultipleTypeConstraints
4+
5+
class X::Parameter::MultipleTypeConstraints does X::Comp { }
6+
7+
Compile time error thrown when a parameter has multiple type constraints.
8+
This is not allowed in Perl 6.0.
9+
10+
Example:
11+
12+
sub f(Cool Real $x) { }
13+
14+
produces
15+
16+
Parameter $x may onle have one prefix type constraint
17+
18+
=head1 Methods
19+
20+
=head2 parameter
21+
22+
Returns the name of the offensive parameter.
23+
24+
=end pod

lib/X/Parameter/Placeholder.pod

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=begin pod
2+
3+
=TITLE class X::Parameter::Placeholder
4+
5+
class X::Parameter::Placeholder does X::Comp
6+
7+
Thrown when a placeholder parameter is used inside a signature where
8+
a normal parameter is expected. The reason is often that a named parameter
9+
C<:$param> was misspelled as C<$:param>.
10+
11+
For example
12+
13+
sub f($:param) { }
14+
15+
produces
16+
17+
===SORRY!===
18+
In signature parameter, placeholder variables like $:param are illegal
19+
you probably meant a named parameter: ':$param'
20+
21+
=head1 Methods
22+
23+
=head2 parameter
24+
25+
The text of the offensive parameter declaration (C<$:param> in the example
26+
above).
27+
28+
=head2 right
29+
30+
Suggestion on how to write the parameter declaration instead (C<:$param> in
31+
the example above).
32+
33+
34+
=end pod

lib/X/Parameter/Twigil.pod

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=begin pod
2+
3+
=TITLE class X::Parameter::Twigil
4+
5+
class X::Parameter::Twigil does X::Comp
6+
7+
Thrown when a parameter in a signature has a twigil that it may not have.
8+
Only C<!>, C<.> and C<*> as twigils are allowed.
9+
10+
Example:
11+
12+
sub f($=foo) { }
13+
14+
produces
15+
16+
===SORRY!===
17+
In signature parameter $=foo, it is illegal to use the = twigil
18+
19+
=head1 Methods
20+
21+
=head2 parameter
22+
23+
The name of the offensive parameter (C<$=foo> in the example above)
24+
25+
=head2 twigil
26+
27+
The illegally used twigil.
28+
29+
=end pod

lib/X/Parameter/WrongOrder.pod

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=begin pod
2+
3+
=TITLE X::Parameter::WrongOrder
4+
5+
class X::Parameter::WrongOrder does X::Comp
6+
7+
Compile time error that is thrown when parameters in a signature in the wrong
8+
order (for example if an optional parameter comes before a mandatory
9+
parameter).
10+
11+
For example
12+
13+
sub f($a?, $b) { }
14+
15+
produces
16+
17+
Cannot put required parameter $b after optional parameters
18+
19+
=head1 Methods
20+
21+
=head2 misplaced
22+
23+
Returns the kind of misplaced parameter (for example C<"mandatory">,
24+
C<"positional">).
25+
26+
=head2 parameter
27+
28+
Returns the name of the (first) misplaced parameter
29+
30+
=head2 after
31+
32+
Returns a string describing other parameters after which the current parameter
33+
was illegally placed (for example C<"variadic">, C<"positional"> or
34+
C<"optional">).
35+
36+
=end pod

lib/X/Phaser/Multiple.pod

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=begin pod
2+
3+
=TITLE class X::Phaser::Multiple
4+
5+
class X::Phaser::Multiple does X::Comp
6+
7+
Thrown when multiple phasers of the same type occur in a block, but only one
8+
is allowed (for example C<CATCH> or C<CONTROL>).
9+
10+
Example
11+
12+
CATCH { }; CATCH { }
13+
14+
Produces
15+
16+
===SORRY!===
17+
Only one CATCH block is allowed
18+
19+
=head1 Methods
20+
21+
=head2 block
22+
23+
Returns the name of the phaser that occured more than once.
24+
25+
=end pod

lib/X/Placeholder/Mainline.pod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ Produces the error message
1515
1616
Cannot use placeholder parameter $^x in the mainline
1717
18+
Note that this error can also occur when you think something is a block,
19+
but it really is a L<< postcircumfix:<{ }> >>, for example
20+
21+
my %h;
22+
say %h{ $^x };
23+
# ^^^^^^^ not a block, so $^x is part of the mainline
24+
1825
=end pod

lib/X/Redeclaration.pod

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=begin pod
2+
3+
=TITLE class X::Redeclaration
4+
5+
class X::Redeclaration does X::Comp { }
6+
7+
Thrown when a symbol (variable, routine, type, paramater, ...) is redeclared.
8+
Note that redeclarations are generally fine in an inner scope, but if the
9+
redeclaration appears in the same scope as the original declaration,
10+
it usually indicates an error and is treated as one.
11+
12+
Examples
13+
14+
my $x; my $x
15+
16+
===SORRY!===
17+
Redeclaration of symbol $x
18+
19+
sub f() { }
20+
sub f() { }
21+
===SORRY!===
22+
Redeclaration of routine f
23+
24+
But those are fine
25+
26+
my $x;
27+
sub f() {
28+
my $x; # not a redeclaration,
29+
# because it's in an inner scope
30+
sub f() { }; # same
31+
}
32+
33+
34+
=head1 Methods
35+
36+
=head2 symbol
37+
38+
Returns the name of the symbol that was redeclared.
39+
40+
=head1 what
41+
42+
Returns the kind of symbol that was redeclared. Usually C<symbol>, but can
43+
also be C<routine>, C<type> etc.
44+
45+
=head1 postfix
46+
47+
Returns a string that is attached to the end of the error message. It
48+
usually explains the particular problem in more detail, or suggests
49+
way to fix the problem.
50+
51+
=end pod

lib/X/Undeclared.pod

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=begin pod
2+
3+
=TITLE class X::Undeclared
4+
5+
class X::Undeclared does X::Comp
6+
7+
Thrown when the compiler encounters a symbol that has not been declared,
8+
but needs to be.
9+
10+
Example
11+
12+
$x
13+
14+
===SORRY!===
15+
Variable $x is not declared
16+
17+
=head1 Methods
18+
19+
=head2 symbol
20+
21+
Returns the name of the undeclared symbol
22+
23+
=head2 what
24+
25+
Returns the kind of symbol that was not declared (for example variable,
26+
type, routine).
27+
28+
Since The symbol wasn't declared, the compiler sometimes has to guess
29+
(or rather disambiguate) what kind of symbol it encounter that wasn't
30+
declared. For example if you write
31+
32+
say a
33+
34+
Then the disambiguation defaults to reporting a missing subroutine, even
35+
though declaring a C<constant a = 'a'> would also make the error go away.
36+
37+
=end pod

0 commit comments

Comments
 (0)