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 checking of defaults #105

Open
schwern opened this issue Aug 6, 2014 · 0 comments
Open

Type checking of defaults #105

schwern opened this issue Aug 6, 2014 · 0 comments

Comments

@schwern
Copy link
Contributor

schwern commented Aug 6, 2014

As of #102 defaults are type checked. This is a side effect of a fix to type check after applying a default. It's probably a waste of CPU to type check constant defaults at runtime.

  1. Type check constant defaults at compile time only.
  2. Type check computed defaults at runtime.

For example.

func hello(
    Str :$place //= "World",
    Str :$greeting //= greeting_for_place($place)
) {
    say "$greeting, $place!";
}

When compiled, the default for $place would be type checked because it is a constant. When run as hello() $place would not be type checked as it is using a constant default. $greeting would be type checked as it is using a computed default. If arguments are passed in for either $place or $greeting they will be type checked.

PPI can probably be used to determine if a default is a constant. Be conservative, it is better to not recognize a complicated constant than to think a computed default is constant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant