Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:18
Show Gist options
  • Select an option

  • Save dacr/1b76c44def82ea3c390c83155e089166 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/1b76c44def82ea3c390c83155e089166 to your computer and use it in GitHub Desktop.
scala3 feature examples - macros - inline sizeOf / published by https://github.com/dacr/code-examples-manager #ec61ceb3-1593-4112-9aa9-6ba76fac74cf/76e89f901b6a0889f086786f34e0e69b3cf8abeb
// summary : scala3 feature examples - macros - inline sizeOf
// keywords : scala3, tutorial, macros, inline, meta-programming, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : ec61ceb3-1593-4112-9aa9-6ba76fac74cf
// created-on : 2021-06-20T12:33:40+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// Inspired from https://www.youtube.com/watch?v=OPBuCQRgyV4&t=1283s from Josh Suereth
//> using scala "3.4.2"
import scala.compiletime.erasedValue
inline def sizeOf[T]: Int =
inline erasedValue[T] match
case _:Byte => 1
case _:Short => 2
case _:Int => 4
case _:Long => 8
case _:Float => 4
case _:Double => 8
@main def go() =
println(s"sizeOf[Int] = ${sizeOf[Int]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment