Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 08:29
    scala-jenkins milestoned #9768
  • 08:06
    NthPortal edited #9768
  • 08:04
    NthPortal labeled #9768
  • 08:04
    NthPortal opened #9768
  • 08:04
    NthPortal labeled #9768
  • 07:46
    nwk37011 synchronize #9752
  • 07:12
    xuwei-k commented on cf1b35b
  • 06:17
    som-snytt commented #12464
  • 05:59
    NthPortal commented #9275
  • 05:45
    NthPortal commented #9388
  • 05:44
    NthPortal commented #12464
  • 05:38
    NthPortal synchronize #9388
  • 05:36
    NthPortal synchronize #9388
  • 05:36
    som-snytt commented #12464
  • 05:35
    NthPortal edited #9388
  • 05:34
    NthPortal edited #9388
  • 05:25
    NthPortal edited #9388
  • 05:18
    NthPortal commented #9388
  • 05:16
    NthPortal synchronize #9388
  • 05:11
    SethTisue commented #12464
Felix Bruckmeier
@felixbr

Hi, I've noticed that getting the name of method parameters seems to have changed between 2.13.4 and 2.13.5.

When I have a method

def listCars(`airport-code`: String): Seq[String] = ???

and try to get the names via

classOf[RentalStation].getMethod("listCars", classOf[String]).getParameters.map(_.getName)

Previously it returned "airport-code" for the parameter and now it seems to return "airport$minuscode". My guess is the internal representation has changed and therefore the java reflection no longer works as expected. Is there any other way to solve this than a bandaid-solution using .replaceAll() ?

(This is not my code, so please don't explain to me that reflection is bad, I know that. I'm just trying to upgrade this very commonly used library)

Luis Miguel Mejía Suárez
@BalmungSan
Maybe using Scala reflection over Java one would provide better results?
(just a pointer, no idea how to do that, sorry)
Felix Bruckmeier
@felixbr
The end goal of my efforts is to make this library Scala 3 compatible. So using scala-reflect might indeed work but introducing it doesn't exactly help with the Scala 3 migration 🙂
Guillaume Martres
@smarter
The names had to be encoded because you can't store any random String as a parameter name
to get back the original names you'd have to decode them
Felix Bruckmeier
@felixbr
Is there a function to do that?
(it's in scala.reflect but it's actually part of scala-library)
Felix Bruckmeier
@felixbr
Thank you, this helps a lot :)
gitleet
@gitleet
does scala3 require a specific java version?
Rob Norris
@tpolecat
8+
gitleet
@gitleet
I have openjdk 14.02
Rob Norris
@tpolecat
I think it should work on any JVM >= 8
Luis Miguel Mejía Suárez
@BalmungSan
Are you getting some error?
gitleet
@gitleet
Why does the scala3 g8 template reference this scala version? https://github.com/scala/scala3.g8/blob/main/build.sbt#L4
2.12.13
Rob Norris
@tpolecat
That's for the g8 template project. The actual template code is down in https://github.com/scala/scala3.g8/tree/main/src/main/g8
gitleet
@gitleet
ah ok! Yes doing scalaVersion shows scala 3.0.0
Elvis Opoku Amoako
@Elvis020
any new things with scala3.0.0??
Rob Norris
@tpolecat
yes lots of new things
Elvis Opoku Amoako
@Elvis020
yaay..havenet had time to check to new stuff out yet, wil do very soon
Rob Norris
@tpolecat
http://dotty.epfl.ch/docs/reference/overview.html <- this section of the doc covers the changes
D Cameron Mauch
@DCameronMauch
Is it possible to create a class alias? I am reading this Spark parquet data, which apparently marks the type of one column as com.vividsolutions.jts.geom.Geometry. But now, in my updated code, it’s called org.locationtech.jts.geom.Geometry. Thus it fails to find an Encoder[Geometry]. I was wondering if I could somehow tell the JVM that the first one is actually at the second one.
heksesang
@heksenlied:matrix.org
[m]
You can create a type alias, might work if I understand your scenario correctly.
ollijh
@liff:matrix.org
[m]
will there ever be better-monadic-for for scala 3?
heksenlied
@heksenlied:matrix.org
[m]
The problems that it was made to solve are fixed in Scala 3, I think.
Rob Norris
@tpolecat
Not entirely fixed but the intent is that they will be. There is an open issue.
Fabio Epifani
@epifab

hello! In scala 2 I could have a type class to prove that another type class instance cannot exist:

sealed trait Negative[A]

object Negative {
  implicit def negative[T](implicit t: T): Negative[T] = new Negative[T] {}
  @implicitAmbiguous("Cannot negate ${T}")
  implicit def positive[T]: Negative[T] = new Negative[T] {}
}

What's the canonical way of achieving this in Scala 3?

heksesang
@heksenlied:matrix.org
[m]
NotGiven
Fabio Epifani
@epifab
awesome! thanks
Marco F.
@mfirry
Ichoran
@Ichoran
@Swoorup - No, Scala doesn't have the equivalent of dbg!, not exactly. You can get something close by building it with https://github.com/com-lihaoyi/sourcecode
Rob Norris
@tpolecat
scala> @implicitNotFound("oops, it's a subtype!") type <:!<[A,B] = NotGiven[A <:< B]
// defined alias type <:!<[A, B] = util.NotGiven[A <:< B]

scala> summon[String <:!< Int]
val res2: util.NotGiven[Nothing] = scala.util.NotGiven@10c23a76

scala> summon[String <:!< Object]
1 |summon[String <:!< Object]
  |                          ^
  |                          oops, it's a subtype!
Neato. The type argument interpolator foo ${A} bar doesn't work on type aliases, hm.
known issue lampepfl/dotty#7092
Guillaume Martres
@smarter
as a side-note, be careful about using a type like the <:!< you defined here, it doesn't mean "A is not a subtype of B", it means "I can't prove that A is a subtype of B"
Rob Norris
@tpolecat
:+1: indeed
idk-kid
@idk-kid

I have a nested schema dataframe.
I wanted to traverse and get some information out.
I was writing this function

def func(struct: StructType) = {
    struct match {
      case StructType(arr) => {
        arr.map{ fields =>
          fields match {
            case StructField(field, dataType, _, _) =>
              dataType match {
                case StructType(_) => func(dataType)
                case ArrayType(structTyp: StructType, _) => func(structTyp)
                case _ => .....
              }
          }
        }
      }
    }
  }

This line case StructType(_) => func(dataType) why is it of type DataType by default?
I tried making it StructType but it said cannot upcast.

Can anybody help?

Luis Miguel Mejía Suárez
@BalmungSan
Try with case struct @ StructType(_) => func(struct)
idk-kid
@idk-kid
So, how does this help? I never used that before
Luis Miguel Mejía Suárez
@BalmungSan
foo @ Bar means match the Bar pattern and if it matches then assign it to foo
In this case, it helps, because struct is of type StructType, which is what you need.
Eric K Richardson
@ekrich

I am really confused by this piece of code and Scala 3 braceless format:

object Foo:
  def joe(): List[(Int, Int)] =
    List((2, 3), (3, 4)).filter { case (a, b) => b > a }

If I remove the {} I get a parser error. If I then wrap the case onto the next line and indent it doesn't like that. I can replace the {} with () but then it doesn't like the case so then I can remove the case and it seems fine with that. I can't wrap the case or without the case to the next line. It is like () is required but is that going to work with a multi-line lambda?

Dan Sokolsky
@dansok
Hi, how to do this properly? --
val logicalPlans: Seq[LogicalPlan] = parsedQuery.collect {
  case logicalPlan >: org.apache.spark.sql.catalyst.plans.logical => logicalPlan
}
I.e., I want to check whether the logicalPlan is of subtype org.apache.spark.sql.catalyst.plans.logical
Rob Norris
@tpolecat
case logicalPlan: org.apache.spark.sql.catalyst.plans.logical => ...
Dan Sokolsky
@dansok
doesn't like it
Rob Norris
@tpolecat
What does it say?
idk-kid
@idk-kid
@BalmungSan it still complains