Comments (1)
I don't nessaserilly agree with the assessment that this is removing an additional check - its simply erroring before you get to the check that you have in both.
If we break down the logic a bit more, in the first example this is trying to break down example into a tuple, and then attempting to pattern match inside of it.
In the second example, a and b do not exist unless you have already successfully run extractors on a Tuple2[Int, Int]
- which is going to fail.
Imagine a case where the inner extractor was not a simple type check, but passing through to some custom unapply method, which accepted only positive Ints, and ascii strings. In this hypothetical, the user in the first case would be asking "Do I have two fields which are either posative ints or ascii strings" and in the second is asking "Do I have exactly two posative ints".
We could also consider examples which were more complex than a simple tuple. For example class Foo[T](foo: Int | T)
. In this case an extractor of Foo[Int](a: int)
is clearly stronger than Foo(a:Int)
- and it would be up to the implementation of Foo.unapply
to determine how this further refinement was handled. In the case of case classes (and thus tuples) - unapply promises to preserve known types - and thus has to fail when the types is wrong.
If we wanted to make this work it would be opening up a whole heap of things in constructs like val Tuple2[Int,Int](a, b) = (???,???)
with a and b not getting the fully validated type.
from scala3.
Related Issues (20)
- Match type with opaque type among cases does not resolve HOT 1
- Cannot do a map on a Map with Scala 3, with Scala 2.13 it works ok HOT 6
- 3.5.0 & 3.5.1-RC2 Release procedure HOT 2
- -Yexplicit-nulls fails to detect null pointer dereference HOT 3
- `-indent` `-rewrite` can produce inparsable code for curried methods taking triple-quote arguments HOT 3
- assertion failed: position not set for new com.augustnagro.magnum.SqlName # -1 of class dotty.tools.dotc.ast.Trees$Select HOT 1
- 3.4.3 Release procedure HOT 1
- Need a way to specify a method's charging a capture set parameter
- Match type fails to reduce when it doesn't look like it needs to reduce
- Nil and LinearSeq cannot be compared HOT 1
- Nightly Dotty workflow of 2024-08-16 failed HOT 2
- Automatic rewrite for `<function> _` can produce non-compiling code for curried functions
- Crash at inlining probably polutes the error reports when inlined value is `Nothing`
- Type mismatch after compiler rewrite for `A with B <:< C`
- Crash in match type with wildcards when using `-Xkind-projector:underscores` HOT 3
- Leaking scoped capabilities HOT 1
- No workaround to dependent-type match types after SIP-56 HOT 6
- Import outside a package clause is not shadowed by an import inside the package clause
- Using full qualifier names for anonymous given naming to avoid double definition HOT 3
- Overloading resolution incorrectly drops alternative with match type result when a target type is provided
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala3.