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

Unexpected level-correctness interaction with type alias #6008

Closed
fhackett opened this issue Mar 2, 2019 · 3 comments
Closed

Unexpected level-correctness interaction with type alias #6008

fhackett opened this issue Mar 2, 2019 · 3 comments

Comments

@fhackett
Copy link
Contributor

fhackett commented Mar 2, 2019

class C {
    type T = Int
    def fn(e : Expr[T]) : Expr[T] = '{ ~e }
}

This fails to compile under Dotty 0.13.0-RC1 (specifically; 0.12.0 accepts this) with the following error:

3 |    def fn(e : Expr[T]) : Expr[T] = '{ ~e }
  |                                       ^^
  |                                access to C.this from wrong staging level:
  |                                 - the definition is at level 0,
  |                                 - but the access is at level 1.

Changing the code like this acts as a workaround:

class C {
    type T = Int
    def fn(e : Expr[Int]) : Expr[T] = '{ ~e }
}

The weird part is that this suddenly started happening in version 0.13.0-RC1. So, either I was taking advantage of a bug that is now fixed, or there is a new bug.

At least, it doesn't make sense to me how adding this layer of indirection changes the meaning of the program. Since it's a plain = alias, there's no chance of T ever not being an Int. In turn, there should be no reason for '{ ~e } to be looking up C.this.

@biboudis
Copy link
Contributor

biboudis commented Mar 4, 2019

Thanks for reporting @fhackett

On a side note this code works on the master branch (note the syntax change due to #5918):

import scala.quoted._

class C {
    type T = Int
    def fn(e : Expr[T]) : Expr[T] = '{ $e }
}

biboudis added a commit to dotty-staging/dotty that referenced this issue Mar 4, 2019
@fhackett
Copy link
Contributor Author

fhackett commented Mar 7, 2019

Hello again - as per our discussion on #6007, I moved my project over to track nightly and found that this issue persists with one tiny difference:

import scala.quoted._

class C {
    type T = Int
    def fn(e : Expr[T]) : Expr[T] = '{ (); $e }
} 

Moving the () to the right of the $e shows the same issue (though fn returns Expr[Unit] then).

@biboudis
Copy link
Contributor

biboudis commented Mar 7, 2019

Thx for reporting!

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

3 participants