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

"final lazy val" field being written outside a constructor #3770

Closed
scabug opened this issue Aug 17, 2010 · 4 comments
Closed

"final lazy val" field being written outside a constructor #3770

scabug opened this issue Aug 17, 2010 · 4 comments
Assignees
Labels

Comments

@scabug
Copy link

@scabug scabug commented Aug 17, 2010

While verifying the bytecode emitted by Scala.NET I noticed a "final lazy val" field being written outside a constructor, something the .NET VM doesn't like.

In package scala.util.regexp there's the following:

abstract class WordExp extends Base {

  abstract class Label

  type _regexpT <: RegExp
  type _labelT <: Label

  case class Letter(a: _labelT) extends RegExp {
    final lazy val isNullable = false
    var pos = -1
  }

  case class Wildcard() extends RegExp {
    final lazy val isNullable = false
    var pos = -1
  }
}

which gets transformed into:

[[syntax trees at end of cleanup]]// Scala source: WordExp.scala
package scala.util.regexp {
  abstract class WordExp extends scala.util.regexp.Base with ScalaObject {
    . . . 
    @serializable case class Wildcard extends scala.util.regexp.Base#RegExp with ScalaObject with Product {

      @volatile protected var bitmap$$0: Int = 0;

      final lazy private[this] var isNullable: Boolean = _; /*- it's a final field */

      final <stable> <accessor> lazy def isNullable(): Boolean = {
        if (Wildcard.this.bitmap$$0.&(1).==(0))
          {
            Wildcard.this.synchronized({
              if (Wildcard.this.bitmap$$0.&(1).==(0))
                {
                  Wildcard.this.isNullable = false; /*- yet it's written outside a constructor. 
                                                        The CLR doesn't like this. */
                  Wildcard.this.bitmap$$0 = Wildcard.this.bitmap$$0.|(1);
                  ()
                };
              scala.runtime.BoxedUnit.UNIT
            });
            ()
          };
        Wildcard.this.isNullable
      };
    . . . 

Is this a bug?

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 17, 2010

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 23, 2010

@lrytz said:
Given

class C { final lazy val t = "abc" }

the classfile marks the private field t as final, but the getter of t assigns to it.

I'ts probably not a bug, i'll let Iuli decide.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 2, 2010

@hubertp said:
I don't think this is a bug, rather a feature :) But I guess we could just reset the final flag for the variable and check if overriding will still throw an error (not sure if the check is done on the accessor or the variable).

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 2, 2010

@hubertp said:
if you agree, Iulian, then I can handle it if you want.

@scabug scabug closed this Dec 13, 2012
@scabug scabug added the won't fix label Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.