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

Check if the parent of class has an empty constr before expanding SAM #15909

Closed
wants to merge 1 commit into from

Conversation

KacperFKorban
Copy link
Member

Expanding a SAM into an anonymous class assumes that the parent class
has a constructor with an empty parameter list. Before this change, a
situation in which there was no such constructor caused a crash.

fixes #15855

Expanding a SAM into an anonymous class assumes that the parent class
has a constructor with an empty parameter list. Before this change, a
situation in which there was no such constructor caused a crash.

fixes scala#15855
@Kordyjan Kordyjan requested a review from odersky August 25, 2022 15:47
@KacperFKorban KacperFKorban removed the request for review from odersky August 25, 2022 15:58
@KacperFKorban
Copy link
Member Author

Looks like there's a case that I missed, converting to draft for now.

@KacperFKorban KacperFKorban marked this pull request as draft August 25, 2022 16:00
@sjrd
Copy link
Member

sjrd commented Aug 25, 2022

These are things that Scala 2 can handle correctly, filling in the appropriate Nil or default value:

$ cs launch scala:2.13.8
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_342).
Type in expressions for evaluation. Or try :help.

scala> class MyFunction(val args: String*)
class MyFunction

scala> trait MyFun[+R] extends MyFunction { def apply(i: Int): R }
trait MyFun

scala> val f: MyFun[Int] = _ + 1
val f: MyFun[Int] = $anonfun$1@2728add3

scala> f(5)
val res1: Int = 6

scala> f.args
val res2: Seq[String] = List()

scala> class MyFunction(val arg: String = "foo")
class MyFunction

scala> trait MyFun[+R] extends MyFunction { def apply(i: Int): R }
trait MyFun

scala> val f: MyFun[Int] = _ + 1
val f: MyFun[Int] = $anonfun$1@2f1b8770

scala> f(5)
val res3: Int = 6

scala> f.arg
val res4: String = foo

@KacperFKorban
Copy link
Member Author

@sjrd Right, I see. Then the fix is going to be entirely different then. Will open a new PR for it then.

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.

Compiler crashes in ExpandSAMs phase
3 participants