Skip to content

Error in code execution order, possibly related to stabilization issues #11397

@soronpo

Description

@soronpo

Possibly related to #10714 which was fixed in scala/scala#6312

The following code demonstrates an error in code execution order.
An assertion placed show exactly where the error occurs.

trait MyAny {
  type TSomething
  type This <: MyAny
}

class MyBool extends MyAny {
  type TSomething = DummyImplicit
  type This = MyBool
}

object Test extends App {
  val i = new MyBool
  var call = 0

  final class MyMatch[MV <: MyAny](val matchVal : MV)  {
    def myCase[MC](pattern : Boolean)(block : => Unit)(
      implicit patternBld : matchVal.TSomething
    ) : MyMatch[MV] = {
      call -= 1
      block
      this
    }
  }

  def myMatch[MV <: MyAny](matchValue : MV) : MyMatch[matchValue.This] = {
    assert(call == 0)
    call += 1
    new MyMatch[matchValue.This](matchValue.asInstanceOf[matchValue.This])
  }

  myMatch(i)
    .myCase(true) {
      myMatch(i)
        .myCase(true) {

        }
    }
}

Affected Scalac version: from 2.13.0-M4
2.13.0-M2 is OK. 2.13.0-M3 causes a crash as demonstrated in #10714
The reason I'm thinking it's related to the stabilization bug is that if we change the code to the following, there is no error:

  myMatch(i)
    .myCase(true) {
      val noErrorNow = myMatch(i)
        .myCase(true) {

        }
    }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions