Context bounds doesn't work sometime
See original GitHub issueCompiler version
3.1.2
Minimized code
trait Sorting:
def sort1[A: ClassTag, B >: A: Ordering, CC](
xs: CC
)(using view: CC => IterableOnce[A], factory: Factory[A, CC]): CC
def sort2[A, B >: A: Ordering, CC](
xs: CC
)(using view: CC => IterableOnce[A], factory: Factory[A, CC])(using ClassTag[A]): CC
Output
val sorting: Sorting = ...
sorting.sort1(Seq(3, 2, 1))
Will got this compile error:
[error] 48 | val actual = sorting.sort(input)
[error] | ^
[error] | No ClassTag available for A
[error] |
[error] | where: A is a type variable with constraint
But sort2
works with no problem:
val sorting: Sorting = ...
sorting.sort2(Seq(3, 2, 1))
Expectation
Based on this article, I think sort1
is just the sort2
with syntactic sugar.
Is it a bug or just a misused case?
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
scala - Using context bounds "negatively" to ensure type class ...
What I'm trying to accomplish is, roughly speaking, "negative evidence". Pseudo code would look something like so: // type class for obtaining serialization ......
Read more >Adjusting Local Context Search Bounds | Maps JavaScript API
You can change the locationRestriction parameter of the LocalContextMapView place search from the default of being strictly bound by the map viewport.
Read more >Visual effect bounds | Visual Effect Graph | 12.0.0
If a System uses Recorded or Automatic bounds, Unity calculates the bounds of the System during the Update Context. This means that any...
Read more >Context-bounded implicit defs sometimes fail to work #7609
Régis Jean-Gilles (rjean-gilles) said: I stumbled upon this very problem and this is very frustrating as I can't find any work around. Note...
Read more >why traits cannot have type parameters with context bounds
Hi list - I am very new to scala just have a error saying 'traits cannot have type parameters with context bounds `:...
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
And we can’t change it, since we need to stay compatible with the way Scala-2 does it.
Note that the current reference doc already describes the actual expansion. It’s just that docs-scala-lang is not updated yet.
https://dotty.epfl.ch/docs/reference/contextual/context-bounds.html