Skip to content

Commit

Permalink
Repro for sbt/zinc#1396
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel committed Sep 18, 2024
0 parents commit 78b154f
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
/.bsp
*.iml
**/target
*.sc

.bloop/
/.metals/
metals.sbt
9 changes: 9 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name := "IncRepro"

//ThisBuild / logLevel := Level.Debug

scalaVersion := "3.5.0"

Compile / incOptions ~= ( _.withTransitiveStep(10) )


1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.10.1
5 changes: 5 additions & 0 deletions src/main/scala/net/opengrabeso/engine/MT.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.opengrabeso.engine

trait MT {
export MTOpaque.Vector3f
}
19 changes: 19 additions & 0 deletions src/main/scala/net/opengrabeso/engine/MTThreeX.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.opengrabeso.engine

import net.opengrabeso.p.OM

import scala.language.implicitConversions

object MTTx {
class DirectSkeleton
}

import MTTx.*

//noinspection ScalaRedundantConversion
trait MTTx extends MT

object MTOpaque {

opaque type Vector3f = tx.Vector3
}
9 changes: 9 additions & 0 deletions src/main/scala/net/opengrabeso/engine/tx.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.opengrabeso.engine

object tx {

case class Vector3(x: Double, y: Double, z: Double)

type DirectSkeleton = MTTx.DirectSkeleton
}

6 changes: 6 additions & 0 deletions src/main/scala/net/opengrabeso/json/ASchema.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.opengrabeso.json

import net.opengrabeso.engine.tx

trait ASchema

64 changes: 64 additions & 0 deletions src/main/scala/net/opengrabeso/json/Schema.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package net.opengrabeso.json

import scala.quoted.*
import scala.reflect.ClassTag

/** Scala 3 specific implementation of ASchema */
object Schema extends ASchema with TypeAccessScala3 {

def getSurface(quotes: Quotes)(classSymbol: quotes.reflect.Symbol): Option[Expr[ClassTag[?]]] = {
given q: Quotes = quotes
import quotes.reflect.*
val subclassType = classSymbol.typeRef
//println(s" Subclass ${subclassType.name} ${classSymbol.flags.is(Flags.Trait)} ${classSymbol.flags.is(Flags.Sealed)}")
Option.when(!classSymbol.flags.is(Flags.Trait) || !classSymbol.flags.is(Flags.Sealed)) { // instead of sealed traits we will list their derived classes
val expr = subclassType.asType match {
case '[t] =>
Expr.summon[ClassTag[t]] match {
case Some(classTagExpr) => classTagExpr.asExprOf[ClassTag[?]]
case None =>
report.error(s"No ClassTag available for type ${Type.show[t]}")
'{???}
}
}
//println(s" Surface of ${subclassType.name} $expr")
expr
}
}

def enumerateSubclassesImpl[T: Type](using Quotes): Expr[List[ClassTag[?]]] = {
import quotes.reflect.*

// Get the symbol of the sealed trait T
val traitSymbol = TypeRepr.of[T].typeSymbol
if (traitSymbol.flags.is(Flags.Sealed)) { // Ensure T is a sealed trait and get its subclasses
//println(s"Subclasses of ${traitSymbol.name}: ${traitSymbol.children.map(_.name).mkString(",")}")
//val process = traitSymbol.children.drop(1).take(1) // good
//val process = traitSymbol.children.take(3) // bad
//val process = traitSymbol.children.take(3).drop(1) // bad
//val process = traitSymbol.children.take(3).drop(2) // bad
// Recursive function to get all subclasses, including indirect ones
def getAllSubclasses(symbol: Symbol): List[Symbol] = {
symbol.children.flatMap { child =>
child :: getAllSubclasses(child)
}
}

// documentation seems unclear, it seems children already include indirect children, but not always (AB children missing)
val process = getAllSubclasses(traitSymbol).distinct

//println(s" processing ${process.map(_.name).mkString(",")}")
val childrenExpr = process.flatMap(getSurface(summon[Quotes])) // 2 good, 3 bad
Expr.ofList(childrenExpr)
} else {
report.error(s"${traitSymbol.fullName} is not a sealed trait")
'{ List.empty[ClassTag[?]] }
}
}

inline def enumerateSubclasses[T]: List[ClassTag[?]] = ${ enumerateSubclassesImpl[T] }
/** helper call for schema derivation of polymorphic sealed trait and classes */
inline def listDerivedClasses[T]: List[TypeDesc] = enumerateSubclasses[T].map(TypeDesc.apply(_))
}


7 changes: 7 additions & 0 deletions src/main/scala/net/opengrabeso/json/TypeAccessScala3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.opengrabeso.json

import scala.reflect.ClassTag

trait TypeAccessScala3 {
case class TypeDesc(ct: ClassTag[?])
}
3 changes: 3 additions & 0 deletions src/main/scala/net/opengrabeso/json/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.opengrabeso

package object json
12 changes: 12 additions & 0 deletions src/main/scala/net/opengrabeso/p/OM.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.opengrabeso.p

class OM extends OMShaders {

override def clone(): OM = {
new OM().copy(this)
}

def copy(source: OM): OM = {
this
}
}
5 changes: 5 additions & 0 deletions src/main/scala/net/opengrabeso/p/OMShaders.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.opengrabeso.p

import net.opengrabeso.p.state.HM

abstract class OMShaders
14 changes: 14 additions & 0 deletions src/main/scala/net/opengrabeso/p/State.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.opengrabeso.p

case class State(timeUs: Long) {

def initFamily(s: State) = {
val a: Any = 0
a match {
case _: state.WC.SimClass.AB =>
None
}

???
}
}
11 changes: 11 additions & 0 deletions src/main/scala/net/opengrabeso/p/World.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.opengrabeso.p

import net.opengrabeso.p.s.SLog

object World {
case class ItemPlacement(houseId: Option[Int], passable: Boolean)
}

case class World(
houses: Map[Int, SLog.HDesc]
)
12 changes: 12 additions & 0 deletions src/main/scala/net/opengrabeso/p/s/SLog.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.opengrabeso.p
package s

import net.opengrabeso.p.state.PWD

object SLog {

case class HDesc() {
def sp: PWD = PWD()
}
}

8 changes: 8 additions & 0 deletions src/main/scala/net/opengrabeso/p/state/HM.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.opengrabeso.p
package state

import World.ItemPlacement

object HM {
val HiddenColor = null
}
19 changes: 19 additions & 0 deletions src/main/scala/net/opengrabeso/p/state/WC.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.opengrabeso.p
package state

import net.opengrabeso.json.Schema

object WC {

/** edit this comment HERE- to trigger compilation */
sealed trait SimClass {
def name: String = this.toString
}

object SimClass {
def derivedClasses = Schema.listDerivedClasses[SimClass]

trait AB
}
}

14 changes: 14 additions & 0 deletions src/main/scala/net/opengrabeso/p/state/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.opengrabeso.p

package object state {

extension (WI: WI) {
def isFor(state: State): Boolean = {
false
}
}

case class WI()

case class PWD()
}

0 comments on commit 78b154f

Please sign in to comment.