Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type check *after* the default is applied. For #102 #103

Merged
merged 3 commits into from Aug 6, 2014
Merged

Conversation

schwern
Copy link
Contributor

@schwern schwern commented Jul 30, 2014

Types were checked before defaults were applied which worked when
defaults could only apply to arguments that weren't passed in. Now that
we have the where clause (and the //= shortcut) you can pass in a value
and still get a default.

func hi( Str $place //= "World" ) { print "Hi, $place!\n" }
hi();      # works
hi(undef); # the 'place' parameter (undef) is not of type Str

This patch fixes that. Type checks are done after defaults are
applied, and args with defaults are now always type checked.

Another consequence is defaults are now type checked. This will now fail.
Object $thing = "string"
This could maybe be optimized by type checking the default once
at compile time.

For #102

Types were checked before defaults were applied which worked when
defaults could only apply to arguments that weren't passed in.  Now that
we have the where clause (and the //= shortcut) you can pass in a value
and still get a default.

    func hi( Str $place //= "World" ) { print "Hi, $place!\n" }
    hi();      # works
    hi(undef); # the 'place' parameter (undef) is not of type Str

This patch fixes that.  Type checks are done after defaults are
applied, and args with defaults are now always type checked.

Another consequence is defaults are now type checked.  This will now fail.
    Object $thing = "string"
This could maybe be optimized by type checking the default once
at compile time.
when doesn't work on 5.8 either, which is puzzling.
barefootcoder added a commit that referenced this pull request Aug 6, 2014
Type check *after* the default is applied.  For #102
@barefootcoder barefootcoder merged commit dfd31a8 into master Aug 6, 2014
@barefootcoder barefootcoder deleted the issue/102 branch August 6, 2014 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants