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.

Typechecking regression in v3.1.2

See original GitHub issue

Compiler version

Works with v3.1.1, fails with v3.1.2 and v3.1.3-RC3.

First bad commit 3ab18a90ac24dba440c498aab6a8f0c763589605

Minimized code

//> using scala "3.1.1"
//> using lib "org.scalacheck::scalacheck:1.16.0"
import scala.reflect.ClassTag
import org.scalacheck.Arbitrary
import org.scalacheck.Gen

trait E[F[_]] {
  type T
  val value: F[T]
  override def toString(): String = s"E($value)"
}

object E {
  def apply[F[_], T1](value1: F[T1]) = new E[F] {
    type T = T1
    val value = value1
  }
}

trait TaggedGen[T] {
  val tag: ClassTag[T]
  val gen: Gen[T]
  override def toString(): String = s"TaggedGen($tag, $gen)"
}
type ETaggedGen = E[TaggedGen]

object TaggedGen {
  def apply[T: ClassTag: Arbitrary] = new TaggedGen[T] {
    val tag = implicitly
    val gen = implicitly[Arbitrary[T]].arbitrary
  }

  def apply[T](tag1: ClassTag[T], gen1: Gen[T]) = new TaggedGen[T] {
    val tag = tag1
    val gen = gen1
  }

  val gen: Gen[ETaggedGen] =
    Gen.oneOf(
      E(apply[Boolean]),
      E(apply[Byte]),
      E(apply[String])
    )

  val gen2: Gen[ETaggedGen] =
    gen.map { etg =>
      implicit val tag = etg.value.tag
      E(TaggedGen(tag, etg.value.gen.filter(_ => true))) // <-- failure here
    }
}

Output

[error] ./test.sc:54:19: Found:    (tag : reflect.ClassTag[etg.T])
[error] Required: reflect.ClassTag[Any]
[error]       E(TaggedGen(tag, etg.value.gen.filter(_ => true)))
[error]                   ^^^
Error compiling project (Scala 3.1.2, JVM)

Expectation

This snippet should continue compiling with scala v3.1.2.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, May 18, 2022

Workaround: give an explicit result type to E.apply:

object E {
  def apply[F[_], T1](value1: F[T1]): E[F] = new E[F] {
    type T = T1
    val value = value1
  }
}

Otherwise the inferred type is E[F] { type T = T1 } which complicates inference since the type E[F] { type T = it.T } is not valid outside the lambda where it is defined.

0reactions
oderskycommented, May 31, 2022

So, can we close this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compilation significantly slower than TSC, and massive ...
Have tried that but it loses all worthwhile type checking. It still takes around 11 seconds on 1.2.1, which is the same speed...
Read more >
Sign in - YouTube
Jamovi 1.2 /1.6 Tutorial: Multivariate Linear Regression (Episode 6) ... This tutorial uses the current build of Jamovi, 1.6. 3 on MacOS.
Read more >
3.4.3 - Simple Linear Regression | STAT 200
In this course, we will be learning specifically about simple linear regression. The "simple" part is that we will be using only one...
Read more >
sklearn.linear_model.LinearRegression
LinearRegression: Principal Component Regression vs Partial Least Squares Regression ... 2])) + 3 >>> reg = LinearRegression().fit(X, y) >>> reg.score(X, ...
Read more >
Chapter 12: Regression: Basics, Assumptions, & Diagnostics
'data.frame': 20 obs. of 3 variables: ## $ subjectID: Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9...
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