Skip to content

Auto getters for Unit parameters reference non existing field #6987

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
kenbot opened this issue Aug 4, 2019 · 2 comments · Fixed by #8080
Closed

Auto getters for Unit parameters reference non existing field #6987

kenbot opened this issue Aug 4, 2019 · 2 comments · Fixed by #8080
Assignees

Comments

@kenbot
Copy link

kenbot commented Aug 4, 2019

Dotty version: 0.17.0-RC1
sbt version: 1.2.7

Code:

enum SingleCase { 
  case TheCase(u: Unit)
}

REPL command:

scala> SingleCase.TheCase(())
Stack trace
java.lang.VerifyError: Bad type on operand stack in putfield
Exception Details:
  Location:
    SingleCase$TheCase.<init>(Lscala/runtime/BoxedUnit;)V @2: putfield
  Reason:
    Type uninitializedThis (current frame, stack[0]) is not assignable to 'SingleCase$TheCase' (constant pool 35)
  Current Frame:
    bci: @2
    flags: { flagThisUninit }
    locals: { uninitializedThis, 'scala/runtime/BoxedUnit' }
    stack: { uninitializedThis, 'scala/runtime/BoxedUnit' }
  Bytecode:
    0000000: 2a2b b500 232a b700 26b1

        at SingleCase$TheCase$.apply(Ex1.scala:5)
        at rs$line$1$.<init>(rs$line$1:1)
        at rs$line$1$.<clinit>(rs$line$1)
        at rs$line$1.res0(rs$line$1)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at dotty.tools.repl.Rendering.$anonfun$3(Rendering.scala:57)
        at scala.Option.map(Option.scala:163)
        at dotty.tools.repl.Rendering.valueOf(Rendering.scala:57)
        at dotty.tools.repl.Rendering.renderVal(Rendering.scala:80)
        at dotty.tools.repl.ReplDriver.displayMembers$3$$anonfun$3(ReplDriver.scala:274)
        at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
        at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
        at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
        at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
        at scala.collection.TraversableLike.map(TraversableLike.scala:237)
        at scala.collection.TraversableLike.map$(TraversableLike.scala:230)
        at scala.collection.AbstractTraversable.map(Traversable.scala:108)
        at dotty.tools.repl.ReplDriver.displayMembers$7(ReplDriver.scala:274)
        at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$3$$anonfun$2(ReplDriver.scala:300)
        at scala.Option.map(Option.scala:163)
        at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$1(ReplDriver.scala:300)
        at dotty.tools.dotc.core.Phases.atPhase$$anonfun$1(Phases.scala:35)
        at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:25)
        at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:35)
        at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:71)
        at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:306)
        at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:230)
        at scala.util.Either.fold(Either.scala:191)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:230)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:182)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
        at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput$$anonfun$2$$anonfun$1(ReplDriver.scala:143)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
        at scala.Console$.withErr(Console.scala:196)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput$$anonfun$1(ReplDriver.scala:143)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
        at scala.Console$.withOut(Console.scala:167)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:143)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
        at xsbt.ConsoleInterface.run(ConsoleInterface.java:52)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)
        at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:199)
        at sbt.Console.console0$1(Console.scala:48)
        at sbt.Console.$anonfun$apply$2(Console.scala:51)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
        at sbt.TrapExit$App.run(TrapExit.scala:253)
        at java.base/java.lang.Thread.run(Thread.java:835)
@bishabosha
Copy link
Member

This is reproduced for any automatic getters generated for parameters of type Unit for classes, case classes and abstract classes, trait parameter lists are not affected by this.

@bishabosha
Copy link
Member

All these fail in present compiler

enum SingleCase { 
  case TheCase1(u: Unit)
}

case class TheCase2(u: Unit)

case class TheCase3(s: String, u: Unit)

class TheCase4(val u: Unit)

abstract class TheCase5(val u: Unit)

@main def demo1 = SingleCase.TheCase1(())
@main def demo2 = TheCase2(())
@main def demo3 = TheCase3("", ())
@main def demo4 = TheCase4(())
@main def demo5 = new TheCase5(()) {}

@bishabosha bishabosha changed the title Enum with a Unit parameter crashes the REPL Auto getters for Unit parameters reference non existing field Aug 14, 2019
@liufengyun liufengyun self-assigned this Jan 20, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 23, 2020
Previously we only check whether an accessor is dropped.
We should check whether the corresponding field is dropped or not.
nicolasstucki added a commit that referenced this issue Jan 24, 2020
Fix #6987: don't generate assignment for dropped fields
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.

3 participants