Skip to content

Lazy enums. #5034

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

Closed
sir-wabbit opened this issue Aug 26, 2018 · 10 comments
Closed

Lazy enums. #5034

sir-wabbit opened this issue Aug 26, 2018 · 10 comments

Comments

@sir-wabbit
Copy link

sir-wabbit commented Aug 26, 2018

It would be great if there were lazy enums with the following encoding:

// Or maybe just by-name parameters?
lazy enum LazyList[+A] {
  case :: (head: => A, tail: LazyList[A])
  case Nil 
}
// >>>
sealed trait LazyList[+A]
object LazyList {
  final class :: [A](_head: => A, _tail: => LazyList[A]) extends LazyList[A] {
    lazy val head: A = _head
    lazy val tail: LazyList[A] = _tail
  }
  final case object Nil extends LazyList[+A]
  // plus *lazy* unapply that doesn't immediately evaluate head or tail
}

But in the meantime, here is a crash:

lazy enum i0
Exception in thread "main" java.lang.AssertionError: assertion failed: illegal flagset combination: lazy abstract <enum> and sealed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:38)
	at dotty.tools.dotc.core.Flags$FlagSet$.$bar$extension(Flags.scala:26)
	at dotty.tools.dotc.ast.DesugarEnums$.addEnumFlags(DesugarEnums.scala:74)
	at dotty.tools.dotc.ast.desugar$.classDef(Desugar.scala:629)
	at dotty.tools.dotc.ast.desugar$.defTree(Desugar.scala:773)
	at dotty.tools.dotc.typer.Namer.expand(Namer.scala:419)
	at dotty.tools.dotc.typer.Namer.index$$anonfun$1(Namer.scala:683)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at dotty.tools.dotc.typer.Namer.index(Namer.scala:683)
	at dotty.tools.dotc.typer.Namer.recur$1(Namer.scala:462)
	at dotty.tools.dotc.typer.Namer.indexExpanded(Namer.scala:479)
	at dotty.tools.dotc.typer.Namer.index(Namer.scala:452)
	at dotty.tools.dotc.typer.FrontEnd.enterSyms$$anonfun$1(FrontEnd.scala:54)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:34)
	at dotty.tools.dotc.typer.FrontEnd.enterSyms(FrontEnd.scala:56)

AE-2251401fe4c14de0510247ea75752a42fcfb237a

skvithalani added a commit to skvithalani/dotty that referenced this issue Aug 31, 2018
@allanrenucci
Copy link
Contributor

Crashes for erased enum as well

allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 27, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 27, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 27, 2018
@nicolasstucki
Copy link
Contributor

machadoit added a commit to machadoit/dotty that referenced this issue Jun 12, 2019
Prevents the compiler from crashing, and returns error instead
machadoit added a commit to machadoit/dotty that referenced this issue Jun 12, 2019
Prevents the compiler from crashing, and returns error instead
@bishabosha
Copy link
Member

this still crashes with the same error:

lazy enum i0 { case A }

@BluePat
Copy link
Contributor

BluePat commented Nov 9, 2019

Well, is help wanted for this issue? Glad to contribute. Or at least try to tackle it.

@bishabosha
Copy link
Member

bishabosha commented Nov 9, 2019

@BluePat PR's are always welcome :), at the very least there should should a sensible user facing error before the assertion crash, probably before/in addEnumFlags

@allanrenucci
Copy link
Contributor

@BluePat There are two stale PRs #5525, #6674. Make sure your fix addresses the comments in these PRs.

@BluePat
Copy link
Contributor

BluePat commented Nov 10, 2019

@bishabosha, @allanrenucci, thanks for the tips. I'll take them into consideration.

@sir-wabbit
Copy link
Author

Same crash:

erased enum

@sir-wabbit
Copy link
Author

Similar crash:

enum A
sealed abstract case
Stack trace
-- [E040] Syntax Error: testing/Test.scala:2:0 ---------------------------------
2 |sealed abstract case
  |^^^^^^
  |'{' expected, but 'end of statement' found
-- [E040] Syntax Error: testing/Test.scala:2:20 --------------------------------
2 |sealed abstract case
  |                    ^
  |                    an identifier expected, but eof found
-- Error: testing/Test.scala:2:7 -----------------------------------------------
2 |sealed abstract case
  |       ^^^^^^^^
  |       abstract modifier cannot be used for objects
exception occurred while typechecking testing/Test.scala
exception occurred while compiling testing/Test.scala
java.lang.AssertionError: assertion failed: illegal flagset combination: sealed case abstract <enum> and <stable> <enum> while compiling testing/Test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: illegal flagset combination: sealed case abstract <enum> and <stable> <enum>
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.core.Flags$given_bits_of_FlagSet$.$bar(Flags.scala:40)
	at dotty.tools.dotc.ast.untpd$Modifiers.$bar(untpd.scala:216)
	at dotty.tools.dotc.ast.DesugarEnums$.expandSimpleEnumCase(DesugarEnums.scala:307)
	at dotty.tools.dotc.ast.DesugarEnums$.expandEnumModule(DesugarEnums.scala:284)
	at dotty.tools.dotc.ast.desugar$.moduleDef(Desugar.scala:886)
	at dotty.tools.dotc.ast.desugar$.defTree(Desugar.scala:1187)
	at dotty.tools.dotc.typer.Namer.expand(Namer.scala:484)
	at dotty.tools.dotc.typer.Namer.index$$anonfun$1(Namer.scala:765)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:305)
	at dotty.tools.dotc.typer.Namer.index(Namer.scala:765)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.completeConstructor(Namer.scala:1133)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:1208)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:843)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:258)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:185)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:187)
	at dotty.tools.dotc.core.Types$NamedType.info(Types.scala:1930)
	at dotty.tools.dotc.core.Types$NamedType.withDenot(Types.scala:2284)
	at dotty.tools.dotc.core.Types$TypeRef$.apply(Types.scala:2473)
	at dotty.tools.dotc.core.Types$NamedType$.apply(Types.scala:2447)
	at dotty.tools.dotc.core.Types$Type.select(Types.scala:1377)
	at dotty.tools.dotc.typer.Typer.loop$2(Typer.scala:299)
	at dotty.tools.dotc.typer.Typer.findRefRecur$1(Typer.scala:345)
	at dotty.tools.dotc.typer.Typer.findRef(Typer.scala:348)
	at dotty.tools.dotc.typer.Typer.typedIdent(Typer.scala:399)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2098)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2176)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2213)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2225)
	at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:2335)
	at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1585)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2103)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2176)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2213)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2225)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2247)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2291)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1910)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2150)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2177)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2213)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2225)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2333)
	at dotty.tools.dotc.typer.FrontEnd.liftedTree1$2(FrontEnd.scala:78)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:83)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:42)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:84)
	at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:114)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:305)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:114)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:161)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:171)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:179)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:186)
	at dotty.tools.dotc.Run.compileSources(Run.scala:123)
	at dotty.tools.dotc.Run.compile(Run.scala:106)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
	at dotty.tools.dotc.Driver.process(Driver.scala:189)
	at dotty.tools.dotc.Driver.process(Driver.scala:158)
	at dotty.tools.dotc.Driver.process(Driver.scala:170)
	at dotty.tools.dotc.Driver.main(Driver.scala:197)
	at dotty.tools.dotc.Main.main(Main.scala)

@allanrenucci
Copy link
Contributor

Fixed in #7850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants