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

Compiler Crashes when Upper-Bounding a Class' Type Parameter with caps.Capability under -Xprint:cc #21646

Closed
bracevac opened this issue Sep 25, 2024 · 5 comments · Fixed by #21678
Assignees
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug itype:crash

Comments

@bracevac
Copy link
Contributor

bracevac commented Sep 25, 2024

Compiler version

3.6.0-RC1-bin-20240924-3f4fee2-NIGHTLY-git-3f4fee2

Minimized code

import language.experimental.captureChecking
import caps.Capability

trait File extends Capability

class Resource[T <: Capability](gen: T):
  def use[U](f: T => U): U = 
    f(gen)

@main def run = 
  val myFile: File = ???
  val r = Resource(myFile)
  ()

Edit: minimized further

Output (click arrow to expand)

[error] ## Exception when compiling 1 sources to /Users/oliver/playground/caps/caps/target/scala-3.6.0-RC1-bin-20240924-3f4fee2-NIGHTLY/classes
[error] dotty.tools.dotc.core.TypeError$$anon$1: invalid new prefix [T <: box caps.Capability^] =>> Test.Resource[box T^] cannot replace Test.Resource in type (Test.Resource#<init> : [T <: box caps.Capability^](gen: T^): Test.Resource[T])
@bracevac bracevac added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label cc-experiment Intended to be merged with cc-experiment branch on origin area:experimental:cc Capture checking related and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 25, 2024
@bracevac
Copy link
Contributor Author

@odersky

@odersky
Copy link
Contributor

odersky commented Sep 27, 2024

I could not reproduce this. #21659 contains the example as a test case (21646.scala). This one compiles with errors but does not crash.

@bracevac
Copy link
Contributor Author

@odersky The exception appears when BOTH the -Xprint:cc compiler option is enabled AND having the upper bound T <: Capability in class Resource.

Say this is in Caps.scala:

//> using scala 3.6.0-RC1-bin-20240918-be10596-NIGHTLY
import language.experimental.captureChecking
import caps.Capability

trait File extends Capability

class Resource[T <: Capability](gen: T):
  def use[U](f: T => U): U = 
    f(gen)

@main def run = 
  val myFile: File = ???
  val r = Resource(myFile)
  ()

and we run

scala compile Caps.scala -O -Xprint:cc

(resp. with scala-cli pre 3.5) then compiler will crash with an exception. It will also happen when compiling via a traditional sbt project using the nightly compiler build.

On the other hand, if we remove the bound <: Capability from T, then the compiler exception will not occur even if -Xprint:cc is enabled.

@bracevac
Copy link
Contributor Author

I can also confirm that this happens with the latest nightly //> using scala 3.nightly

@bracevac bracevac changed the title Compiler Crashes when Upper-Bounding a Class' Type Parameter with caps.Capability Compiler Crashes when Upper-Bounding a Class' Type Parameter with caps.Capability under -Xprint:cc Sep 30, 2024
@bracevac bracevac self-assigned this Sep 30, 2024
@bracevac
Copy link
Contributor Author

The problem appears to be in the show method of class Recheck respectively the TreeMap used in addRecheckedTypes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants