by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 30 22:39
    pgrandjean commented #257
  • May 30 22:39
    pgrandjean commented #257
  • May 30 22:35
    pgrandjean synchronize #257
  • May 30 22:35
    pgrandjean synchronize #257
  • May 26 07:04
    taeguk opened #258
  • May 26 07:04
    taeguk opened #258
  • May 17 23:21
    pgrandjean synchronize #257
  • May 17 23:21
    pgrandjean synchronize #257
  • May 17 23:17
    pgrandjean synchronize #257
  • May 17 23:17
    pgrandjean synchronize #257
  • May 17 23:09
    pgrandjean commented #254
  • May 17 23:09
    pgrandjean commented #254
  • May 17 23:05
    pgrandjean opened #257
  • May 17 23:05
    pgrandjean opened #257
  • May 17 10:16
    propensive labeled #254
  • May 17 10:16
    propensive labeled #254
  • May 17 10:16
    propensive labeled #254
  • May 17 10:16
    propensive labeled #254
  • May 17 10:16
    propensive labeled #254
  • May 17 10:16
    propensive labeled #254
Georgi Krastev
@joroKr21
It might be fixable though, I'm not sure
You can ignore sealed traits though by just not defining dispatch
Barnabás Oláh
@stsatlantis
@joroKr21 I would like to ignore the combine not the dispatch :/
Maybe you can share the problematic code in Scastie?
Just a sec.
Barnabás Oláh
@stsatlantis

I scastie it works, maybe it's a local setup. but here is a minimal example:
https://github.com/stsatlantis/magnolia-test what produces the the compilation error:

 /Users/barnabasolah/workplace/oss/magnolia-test/src/main/scala/test/Csv.scala:26:54: macro implementations cannot have implicit parameters other than WeakTypeTag evidences
[error]   implicit def deriveCsv[A]: Csv[A] = macro Magnolia.gen[A]

I'm using openjdk:11

Georgi Krastev
@joroKr21
Might be missing scala-reflect at compile time?
That was a recent change
Barnabás Oláh
@stsatlantis
thanks, that was the problem :) after explicitly adding scala-reflect to the dependencies solved the issue :)
Barnabás Oláh
@stsatlantis
After finding propensive/magnolia#235 I got the answer why it's been excluded as well :)
Barnabás Oláh
@stsatlantis

About ignoring case classes - that sounds weird to me. Sealed traits eventually have to implemented by something (case classes or case objects)

My use case is: I have several Events and each event has to have a way to define partitionKey, I opted to provide it via type class HasPartitionKey[T]

// relevant imports
def createRequest[A:HasPartitionKey](event: A) : Request= ???



object HasPartitionKey{
//no need for combine

def dispatch[A](ctx: SealedTrait[HasPartitionKey, A]): HasPartitionKey[A] = new HasPartitionKey[A] {
    def apply(a: A): String =
      ctx.dispatch(a)(sub => sub.typeclass(sub.cast(a)))
  }
}

sealed trait Event
object Event {
  case class AppleHarvested(field: String) extends Event
  case object HarvestOver extends Event

 // HasPartitionKey instances ...



  implicit def deriveCsv[A]: Csv[A] = macro Magnolia.gen[A]

}

def sendEvent(e: Event) = {
...
val request = createRequest(e)
...
}

Actually when the combine is called I would like to throw and exception at compile time, as you mentioned @implicitNotFound or this would require rewriting of the macro which relies on the combine method. ?

Georgi Krastev
@joroKr21
To make @implicitNotFound we would have to do changes in Magnolia
But if you simply do not define combine it will ofc not compile
Kai
@neko-kai
@stsatlantis You need to add scala-reflect dependency. libraryDependencies += “org.scala-lang” % “scala-reflect” % scalaVersion.value
Matthias Berndt
@mberndt123
I've noticed that magnolia seems to pull in the scala-compiler jar into the run-time classpath
Kai
@neko-kai
@mberndt123 Fixed in 0.15.0
Matthias Berndt
@mberndt123
thanks
Matthias Berndt
@mberndt123
No, it's not fixed
It's still pulled in via mercator
mercator 0.2.1 has a normal (non-"Provided") dependency on scala-compiler, and magnolia 0.15.0 depends on mercator 0.2.1
Am I missing something here?
Kai
@neko-kai
Right
Matthias Berndt
@mberndt123
Why not fix it in mercator?
I think it should be enough to put scala-compiler in the Provided configuration in that project
I've made a pull request in mercator
Matthias Berndt
@mberndt123
Georgi Krastev
@joroKr21
:thumbsup:
We can do both. Then when updating Mercator in Magnolia should remember to remove the exclusions
Matthias Berndt
@mberndt123
Well the problem is that mercator seems to be a bit dead, given that CI doesn't pass and hasn't since January
Georgi Krastev
@joroKr21
:(
Matthias Berndt
@mberndt123

We can do both. Then when updating Mercator in Magnolia should remember to remove the exclusions

I don't think adding an exclusion in magnolia will do anything useful, because we still need to have mercator in the dependencies, and ivy is going to pull in transitive dependencies, including mercator's.

Georgi Krastev
@joroKr21
Hmm shouldn't it ignore dependencies which are excluded?
Kai
@neko-kai

@mberndt123 Not true, both coursier and ivy obey exclusions in the pom. If you don’t depend on mercator directly, it’s transitives will not be pulled - otherwise exclusions would’ve been useless. You can check the resolution with coursier resolve command, and you can pull all the jars with coursier too:

[~] % coursier resolve com.propensive:magnolia_2.13:0.15.0
com.propensive:magnolia_2.13:0.15.0:default
com.propensive:mercator_2.13:0.2.1:default
jline:jline:2.14.6:default
org.scala-lang:scala-compiler:2.13.0:default
org.scala-lang:scala-library:2.13.1:default

[~] % coursier resolve com.propensive:magnolia_2.13:0.14.5
com.propensive:magnolia_2.13:0.14.5:default
com.propensive:mercator_2.13:0.2.1:default
jline:jline:2.14.6:default
org.scala-lang:scala-compiler:2.13.0:default
org.scala-lang:scala-library:2.13.1:default
org.scala-lang:scala-reflect:2.13.0:default

Note how 0.15 lacks the scala-reflect jar. The only difference between them is exclusions

Ok, I can’t vouch for ivy 100% because i can’t test it rn, but we’ve used exclusions long before coursier and they worked, so i assume it must have respected them too
Matthias Berndt
@mberndt123
Oh, I didn't know that exclusions also end up in the POM
Good to know, thanks
Matthias Berndt
@mberndt123
neat!
Kai
@neko-kai
@propensive could we get a new release with the another recent exclusion? Thanks!
ivan-klass
@ivan-klass
Hi everyone! Could anyone please clarify why CaseClass[_, T] may have empty typeName.typeArguments while there is type argument in the case class ? Thanks
Ah, looks like I've found the bug. gen[MyTypeClass[Foo[Bar]]] // typeArguments are OK object Baz { type Type = MyTypeClass[Foo[Bar]] } gen[Baz.Type] // typeArguments are empty
Georgi Krastev
@joroKr21
Well depends on your point of view if this is a bug or not :smile:
som-snytt
@som-snytt
@propensive not on twitter, but you asked about a post-typer hook. Compilation unit has a simple list of units of work to run after typer. c.enclosingUnit.asInstanceOf[global.CompilationUnit].toCheck += (() => println(s"*** $text ***")) It seems very easy to abuse. https://gist.github.com/som-snytt/b0a447ccc4555a4947c0eab33948db39
Georgi Krastev
@joroKr21
Oh wow that's nice
som-snytt
@som-snytt
Probably propensive doesn't check gitter.
som-snytt
@som-snytt
Maybe @tpolecat will forward the hot tip via twitter, as his twitter must be where I read the question. Hot tips and hot sauce.
Rob Norris
@tpolecat
The compiler API is not part of my reality. I tried to read your gist but my brain substituted a photo of a hissing possum.
som-snytt
@som-snytt
It was actually that fuzzy baby possum. Since they kicked me off twitter, I should just stop reading twitter altogether. Edit: I meant to say, it only matters if propensive actually needs it for something.
oybek
@oybek

Hello guys, can you tell me what am I doing wrong:


import cats.Show
import magnolia._

import scala.language.experimental.macros

object ShowDeriver {
  type TypeClass[T] = Show[T]

  def combine[T](caseClass: CaseClass[TypeClass, T]): Show[T] = (t: T) => {
    val paramShows = caseClass.parameters.map { p =>
      p.label + "=" + p.typeclass.show(p.dereference(t))
    }
    caseClass.typeName + paramShows.mkString("(", ",", ")")
  }

  def dispatch[T](sealedTrait: SealedTrait[Show, T]): Show[T] = (t: T) => sealedTrait.dispatch(t) { subtype =>
    subtype.typeclass.show(subtype.cast(t))
  }

  implicit def gen[T]: Show[T] = macro Magnolia.gen[T]
}

Here is app:

import cats.Show
import cats.implicits._

case class Student(name: String, age: Int)

object TheApp extends App {
  implicit val show = ShowDeriver.gen[Student]

  val s = Student("john", 23).show
  println(s)
}

But I'm getting this:

[error] /home/oybek/Garage/magnolia-exp/src/main/scala/TheApp.scala:7:38: magnolia: the derivation object ShowDeriver does not define the Typeclass type constructor
[error]   implicit val show = ShowDeriver.gen[Student]
[error]                                      ^
[error] /home/oybek/Garage/magnolia-exp/src/main/scala/TheApp.scala:9:31: value show is not a member of Student
[error]   val s = Student("john", 23).show
[error]                               ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 15 s, completed May 31, 2020 4:23:07 PM
Dmytro Mitin
@DmytroMitin
@oybek It should be Typeclass instead of TypeClass?
oybek
@oybek
@DmytroMitin it worked - thanks a lot, I thought it was just an identifier, that is why renamed to camelCase )