refined icon indicating copy to clipboard operation
refined copied to clipboard

Modified singletonWitnessAs to use valueOf instead of constValue for Scala 3

Open mpskowron opened this issue 2 years ago • 1 comments

This doesn't compile for Scala 3.0.1

import eu.timepit.refined.generic.Equal
import eu.timepit.refined.collection.Size
import eu.timepit.refined.refineV

val size = 2

val arr = refineV[Size[Equal[size.type]]](Array(1, 2))

Error message:

  |val arr = refineV[Size[Equal[size.type]]](Array(1, 2))
  |                                                      ^
  |                 not a constant type: (size : Int); cannot take constValue
  | This location contains code that was inlined from WitnessAs.scala:39

However, this does compile:

import eu.timepit.refined.generic.Equal
import eu.timepit.refined.collection.Size
import eu.timepit.refined.refineV
import eu.timepit.refined.internal.WitnessAs

inline given singletonWitnessAs[B, A <: B: ValueOf]: WitnessAs[A, B] = {
  val a = valueOf[A]
  WitnessAs(a, a)
}
val size = 2
val arr = refineV[Size[Equal[size.type]]](Array(1, 2))

Using refined with modified "signletonWitnessAs" also compiles. I don't know if this is correct fix for the issue, hope it is.

mpskowron avatar Jul 26 '21 20:07 mpskowron

Codecov Report

Merging #998 (f76973a) into master (01c5220) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #998   +/-   ##
=======================================
  Coverage   92.39%   92.39%           
=======================================
  Files          63       63           
  Lines         815      815           
  Branches        6        6           
=======================================
  Hits          753      753           
  Misses         62       62           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 01c5220...f76973a. Read the comment docs.

codecov[bot] avatar Jul 26 '21 20:07 codecov[bot]