Skip to content

Commit

Permalink
If optional parameter not supplied, don't do type checks. Resolves RT…
Browse files Browse the repository at this point in the history
…#61528 and RT#63048.
  • Loading branch information
jnthn committed Feb 11, 2009
1 parent 2e70f2d commit 4367761
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/classes/Signature.pir
Expand Up @@ -307,14 +307,19 @@ lexicals as needed and performing type checks.
name = param['name']
if name == 'self' goto param_loop
sigil = substr name, 0, 1
.local pmc type, orig, var
.local pmc type, optional, orig, var
type = param['type']
optional = param['optional']
orig = callerlex[name]
if sigil == '@' goto param_array
if sigil == '%' goto param_hash
if sigil != '$' goto param_sub
var = '!CALLMETHOD'('Scalar', orig)
## typecheck the argument
## typecheck the argument unless it's undef (for optional parameter)
if null optional goto not_optional
$I0 = defined orig
unless $I0 goto param_val_done
not_optional:
if null type goto param_val_done
.lex '$/', $P99
$P0 = type.'ACCEPTS'(var)
Expand Down
5 changes: 4 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -1092,10 +1092,13 @@ method signature($/, $key) {
my $sigparam := PAST::Op.new( :pasttype('callmethod'),
:name('!add_param'), $sigobj, $name );

## if it's named, note that in the signature object
## if it's named or optional, note that in the signature object
if $var.named() ne "" {
$sigparam.push(PAST::Val.new( :value($var.named()), :named('named') ));
}
if $var.viviself() {
$sigparam.push(PAST::Val.new( :value(1), :named('optional') ));
}

## add any typechecks
my $type := $var<type>;
Expand Down

0 comments on commit 4367761

Please sign in to comment.