Matching an AnyVal with private constructor
See original GitHub issueI’m not sure if it’s limited to AnyVals or applies to any class with a private constructor, but it seems to be impossible to match arguments of such type.
Pseudo-example:
final case class CountryCode private (value: String) extends AnyVal
object CountryCode extends LazyLogging {
def apply(code: String): Either[String, CountryCode] = { ... }
}
}
foo.bar(any[CountryCode]).returns(baz)
fails compilations with
constructor CountryCode in class CountryCode cannot be accessed in <$anon: org.mockito.matchers.DefaultValueProvider[CountryCode]> from <$anon: org.mockito.matchers.DefaultValueProvider[CountryCode]>
.bar(any[CountryCode])
I haven’t found a workaround for now
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Does having a private constructor on a value class negate the ...
A case class extending AnyVal must be a top-level class; i.e. cannot be nested within the scope of another class, trait, or object....
Read more >Scala - AnyVal meets Pattern Matching - LinkedIn
class Month(private val n:Int) extends AnyVal{ override def toString: ... in pattern matching based on the parameters to the constructor, ...
Read more >Value Classes and Universal Traits - Scala Documentation
0, value classes are a mechanism in Scala to avoid allocating runtime objects. This is accomplished through the definition of new AnyVal subclasses....
Read more >[Solved]-Does having a private constructor on a value class negate ...
A case class extending AnyVal must be a top-level class; i.e. cannot be nested within the scope of another class, trait, or object....
Read more >AnyVal - Scala 3 - EPFL
AnyVal is the root class of all value types, which describe values not implemented as objects in the ... cannot be used in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Scala version? (iirc on each version I use a different ~hack~ impl 😂 )
Right! I haven’t thought of that 😃 Thanks.
You can keep this issue open if you’d like to improve the error message, otherwise, feel free to close.