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.

BitSet does not conform to Set[Int] in match type

See original GitHub issue

Compiler version

3.1.3-RC1-bin-20220228-fa08d00-NIGHTLY

Minimized code

import scala.collection.immutable.BitSet

type SetFor[A] <: Set[A] = A match
  case Int => BitSet
  case A => Set[A]

Output

  case Int => BitSet
              ^^^^^^
              Found:    collection.BitSet
              Required: Set[A]

Expectation

Compile and match correctly.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dwijnandcommented, Mar 2, 2022

Btw, I also tried to find something that works and failed, and can’t tell exactly why it fails while LeafElem and leafElem work. Perhaps it’s some solace. 🙂 I’m not never sure where match type questions are being asked and answered…

1reaction
dwijnandcommented, Mar 1, 2022

I assume there was just an error in reproduction or minimisation and you meant scala.collection.immutable.BitSet, as in:

import scala.collection.immutable.BitSet

type SetFor[A] <: Set[A] = A match
  case Int => BitSet
  case A => Set[A]

Here’s the -explain output:

-- [E007] Type Mismatch Error: tests/pos/i14593.scala:2:41 -----------------------------------------------------------------------
2 |  case Int => scala.collection.immutable.BitSet
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |              Found:    collection.immutable.BitSet
  |              Required: Set[A]
  |-------------------------------------------------------------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: scala.collection.immutable.BitSet
  | I tried to show that
  |   collection.immutable.BitSet
  | conforms to
  |   Set[A]
  | but the comparison trace ended with `false`:
  |
  |   ==> collection.immutable.BitSet  <:  Set[A]
  |     ==> Set[Int]  <:  Set[A] (left is approximated)
  |       ==> (scala.collection.immutable : scala.collection.immutable.type)  <:  collection.immutable.type
  |       <== (scala.collection.immutable : scala.collection.immutable.type)  <:  collection.immutable.type = true
  |       ==> A  <:  Int
  |         ==> Any  <:  Int (left is approximated)
  |         <== Any  <:  Int (left is approximated) = false
  |       <== A  <:  Int = false
  |     <== Set[Int]  <:  Set[A] (left is approximated) = false
  |   <== collection.immutable.BitSet  <:  Set[A] = false
  |
  | The tests were made under the empty constraint
   -------------------------------------------------------------------------------------------------------------------------------

So looks like when A is matched with Int, A := Int (or perhaps A =:= Int) isn’t added to the constraints such that this is true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no match for operator - c++
I am trying to write a function that asks the user to input multiple hex strings to a console and then convert those...
Read more >
BitSet
A BitSet is not safe for multithreaded use without external synchronization. ... public void set (int fromIndex, int toIndex, boolean value).
Read more >
Bit Array and Bit Set API Review (The end of a GSoC Project)
As BitSet is essentially a Set<Int> in its API. Therefore, not conforming to SetAlgebra is naturally an interesting choice. Instead, useful ...
Read more >
C++ Standard Library Defect Reports and Accepted Issues
Returns: An object of type bitset<N>::reference such that (*this)[pos] ... that can be passed to a locale constructor, but there is no matching...
Read more >
std::bitset
The class template bitset represents a fixed-size sequence of N bits. Bitsets can be manipulated by standard logic operators and converted ...
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