Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Feb 11, 2019

No description provided.

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition would be that SAM type creation of sealed classes should be allowed within the same file, however scalac prevents it.

if (!isFullyDefined(pt, ForceDegree.all))
ctx.error(ex"result type of closure is an underspecified SAM type $pt", tree.sourcePos)
ctx.error(ex"result type of lambda is an underspecified SAM type $pt", tree.sourcePos)
else if (pt.classSymbol.is(FinalOrSealed)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this check into the SAMType extractor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I think it's better here. An extractor is for extracting, not reporting errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to report an error in the extractor, just have the extractor return None on sealed and final classes. It seemed arbitrary to have a special error message for this. In scalac I get a type mismatch instead.:

scala> sealed trait Foo { def f(x: Int): Int }; val foo: Foo = (x: Int) => x
<console>:11: error: type mismatch;
 found   : Int => Int
 required: Foo
       sealed trait Foo { def f(x: Int): Int }; val foo: Foo = (x: Int) => x

@odersky
Copy link
Contributor Author

odersky commented Feb 11, 2019

Even anonymous subclasses of sealed types are problematic. So I think it's OK to not allow SAM type creation.

if (!isFullyDefined(pt, ForceDegree.all))
ctx.error(ex"result type of closure is an underspecified SAM type $pt", tree.sourcePos)
ctx.error(ex"result type of lambda is an underspecified SAM type $pt", tree.sourcePos)
else if (pt.classSymbol.is(FinalOrSealed)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to report an error in the extractor, just have the extractor return None on sealed and final classes. It seemed arbitrary to have a special error message for this. In scalac I get a type mismatch instead.:

scala> sealed trait Foo { def f(x: Int): Int }; val foo: Foo = (x: Int) => x
<console>:11: error: type mismatch;
 found   : Int => Int
 required: Foo
       sealed trait Foo { def f(x: Int): Int }; val foo: Foo = (x: Int) => x

@odersky odersky merged commit aa715fe into scala:master Feb 15, 2019
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.

2 participants