question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Context bounds doesn't work sometime

See original GitHub issue

Compiler 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:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Jun 10, 2022

And we can’t change it, since we need to stay compatible with the way Scala-2 does it.

0reactions
oderskycommented, Jun 10, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found