Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Dec 12, 2019

Implements the scheme described in my comment to #7546.

  • We type check an argument without or with flow info,
    depending on whether the function part of the application
    is known to take a call-by-name parameter. If we know nothing
    about the function part, we assume call-by-value.
  • At the end of type checking an application, if the argument is
    known to be by-name, remove all x.$asInstanceOf$[T] casts in the
    argument where x is a mutable variable, and run the (re-)typer again
    on the result. If this succeeds and gives a type that is still compatible
    with the formal parameter type, we are done.
  • Otherwise, issue an error saying that the argument cannot be treated
    as call-by-name since it contains flow-assumptions about mutable variables.
    As a remedy, suggest to wrap the argument in a scala.compiletime.byName(...)
    call. Here, byName is defined as follws:
    inline def byName[T](x: => T): T 
    Wrapping an argument with byName means that we know statically that
    it is passed to a by-name parameter, so it will be typechecked without
    flow info.
Implements the scheme described in my comment to scala#7546. - We type check an argument without or with flow info, depending on whether the function part of the application is known to take a call-by-name parameter. If we know nothing about the function part, we assume call-by-value. - At the end of type checking an application, if the argument is known to be by-name, remove all x.$asInstanceOf$[T] casts in the argument where x is a mutable variable, and run the type assigner (not the type checker!) again on the result. If this succeeds and gives a type that is still compatible with the formal parameter type, we are done. - Otherwise, issue an error saying that the argument cannot be treated as call-by-name since it contains flow-assumptions about mutable variables. As a remedy, suggest to wrap the argument in a `scala.compiletime.byName(...)` call. Here, `byName` is defined as follws: ``` inline def byName[T](x: => T): T ``` Wrapping an argument with byName means that we know statically that it is passed to a by-name parameter, so it will be typechecked without flow info.
@odersky odersky force-pushed the change-byname-nullable branch from a0e3525 to df71c9a Compare December 14, 2019 09:53
@odersky odersky merged commit 0d950fb into scala:master Dec 14, 2019
@odersky odersky deleted the change-byname-nullable branch December 14, 2019 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants