Skip to content

TASTy generated for AnyVal with non-val param is invalid #19307

Open
@sjrd

Description

@sjrd

Compiler version

3.3.1

Minimized code

class ValueClassNonVal(self: String) extends AnyVal:
  def get: String = self // TERMREFsymbol, OK
  def getThroughThis: String = this.self // SELECT, ~OK because this prefix

  // def getOther(that: ValueClassNonVal): String = that.self // does not compile, rightly so

  // <generated>
  def equals(x$0: Any): Boolean = x$0 match
    case x$0: ValueClassNonVal =>
      this.self // SELECT, ~OK because this prefix
        == x$0.self // SELECT, definitely not OK
    case _ =>
      false
end ValueClassNonVal

Output

    80:       DEFDEF(73) 20 [equals]
    83:         PARAM(5) 21 [x$0]
    86:           TYPEREF 22 [Any]
    88:             SHAREDtype 19
    90:         TYPEREF 23 [Boolean]
    92:           SHAREDtype 19
    94:         MATCH(57)
    96:           TERMREFdirect 83
    98:           CASEDEF(46)
   100:             BIND(26) 21 [x$0]
   103:               SHAREDtype 70
   105:               TYPED(20)
   107:                 IDENT 24 [_]
   109:                   ANNOTATEDtype(14)
   111:                     SHAREDtype 70
   113:                     APPLY(10)
   115:                       SELECTin(8) 27 [<init>[Signed Signature(List(),scala.unchecked) @<init>]]
   118:                         NEW
   119:                           TYPEREF 25 [unchecked]
   121:                             SHAREDtype 19
   123:                         SHAREDtype 119
   125:                 SHAREDtype 109
   127:               SYNTHETIC
   128:             APPLY(16)
   130:               SELECTin(10) 30 [==[Signed Signature(List(java.lang.Object),scala.Boolean) @==]]
   133:                 SELECT 3 [self]
   135:                   QUALTHIS
   136:                     IDENTtpt 2 [ValueClassNonVal]
   138:                       SHAREDtype 70
   140:                 SHAREDtype 86
   142:               SELECT 3 [self] // <-- PROBLEM HERE
   144:                 TERMREFdirect 100
   146:           CASEDEF(5)
   148:             IDENT 24 [_]
   150:               SHAREDtype 86
   152:             FALSEconst
   153:         OVERRIDE
   154:         SYNTHETIC

Normally, a SELECT cannot point to a PRIVATE | LOCAL field. There is an exception if the prefix is a ThisType, to be able to access local params from my own class. But it is not possible to refer to a PRIVATE | LOCAL field through any other prefix.

Here, the TASTy that gets generated does precisely the thing that's not possible. In fact, if we try to write the code by hand, it does not compile.

Expectation

Either the self param should not have the LOCAL flag, or the generated equals method should use another way of accessing that value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions