zio / zio-prelude

A lightweight, distinctly Scala take on functional abstractions, with tight ZIO integration

Home Page:https://zio.dev/zio-prelude

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Smartypes in Subtypes don't work + error message wrong

domdorn opened this issue · comments

  object SampleType extends zio.prelude.Subtype[Double] {
    override def assertion = assert {
      greaterThanOrEqualTo(0.0d) && lessThanOrEqualTo(1.0d)
    }
  }
  type SampleType = SampleType.Type

  def someTest(): SampleType = {

    val value = Math.random()
    SampleType(value)
  }

boom!
[error]  Newtype Assertion Failed
[error] Could not validate Assertion at compile-time.
[error] Either use a literal or call "com.acme.cc.types.`package`.SampleType.unsafeWrap(Expr[Nothing](value))"
[error]     SampleType(value)

However, there is no unsafeWrap declared in SampleType

Perhaps the error message could say something like "Cannot validate runtime value at compile-time. Use make instead." or something to that effect so that it directs users to the right method.