PurpleKingdomGames / ultraviolet

Scala 3 to GLSL transpiler library
https://ultraviolet.indigoengine.io/
MIT License
59 stars 2 forks source link

Upgrading to Scala 3.3.0 #88

Closed davesmith00000 closed 1 year ago

davesmith00000 commented 1 year ago

Upgrades Ultraviolet to Scala 3.3.0, as well as other deps and the examples..

The only thing to really know is that calling external inlined functions doesn't work the way it used to. Here's a simple example...

Given an object called Importable:

object Importable:
  inline def addOne = (i: Int) => i + 1

In Scala 3.2.x

This used to work:

import Importable.*

inline def fragment: Shader[FragEnv, Int] =
  Shader { _ =>
    val value = 10
    addOne(value)
  }

Scala 3.3.x

Unfortunately the way inlines are represented in the AST has now changed, and the old method does not work anymore. Luckily there is a simple, if boring, workaround. All we have to do is create a local proxy with the same signature that delegates to the original function:

import Importable.*

inline def fragment: Shader[FragEnv, Int] =
  Shader { _ =>
    val proxy: Int => Int = addOne
    val value = 10
    proxy(value)
  }