Giter VIP home page Giter VIP logo

Comments (5)

nicolasstucki avatar nicolasstucki commented on May 25, 2024

Annother test case

//  decoder_1.scala
trait Decoder
object Decoder:
  given foo: Int = ???

def bar(using d: M[Decoder]): Any = ???

type M[Y] = Y match
  case Decoder => Int
// test_2.scala
// should fail, does when compiling at the same time as decoder_2.scala
def test: Unit = bar

from scala3.

nicolasstucki avatar nicolasstucki commented on May 25, 2024

This is a minimization from tests/pos/i15183 when compiling the two files at the same time.

from scala3.

odersky avatar odersky commented on May 25, 2024

Bar[Decoder] has type

(using d: DecoderToInt[Decoder]): Any

Decoder appears in that type, so it is in the implicit scope.

I think the issue has rather to do with match types. Sometimes they are resolved sometimes not, and the implicit scope is different for the two versions.

from scala3.

odersky avatar odersky commented on May 25, 2024

I can confirm, that's excactly what happens. decoder and test are run together, M[Decoder] is simplified to Int, so Decoder does not reduce to the implicit scope. But if we compile test_2 separately, we still see an M[Decoder].

from scala3.

EugeneFlesselle avatar EugeneFlesselle commented on May 25, 2024

A related minimisation, where inference rather than implicit search, is impacted by whether or not the match type is reduced.

type MyMap[X] <: Any = X match
  case Double => Int

def myMap[T]: MyMap[T] = ???
def derived(d: MyMap[Double]): Any = ???

val der = derived(myMap)
-- [E007] Type Mismatch Error: tests/pos/i15183b.scala:10:18 -----------------------------------------------------------
10 |val der = derived(myMap)
   |                  ^^^^^
   |                  Found:    MyMap[T]
   |                  Required: Int
   |
   |                  where:    T is a type variable
   |
   |
   |                  Note: a match type could not be fully reduced:
   |
   |                    trying to reduce  MyMap[T]
   |                    failed since selector T
   |                    does not match  case Double => Int
   |                    and cannot be shown to be disjoint from it either.
   |
   | longer explanation available when compiling with `-explain`

But the same code is accepted when moving der into a separate file and compiling with a classpath dependency.

from scala3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.