Giter Site home page Giter Site logo

Comments (8)

romac avatar romac commented on May 12, 2024

I only realised now that the firs testcase above only relies on wildcards, not full-blown existentials (ie. existential types which pass this condition).

While adding support for wildcards doesn't seem out of my reach, they won't actually prove very useful for my use-case, where I actually need something akin to:

trait Wrap {
  type Inner
  def foo: Inner
  def bar(toto: Inner): Wrap
}

def other(a: Int): Wrap = new Wrap { /* ... */ }

val wrapped = new Wrap {
  type Inner = Int
  def foo = 42
  def bar(toto: Int): Wrap = other(toto + bar)
}

I am thus wondering whether I should resuscitate my anonymous classes branch, and then look into associated types/type aliases. What do you think?

from stainless.

jad-hamza avatar jad-hamza commented on May 12, 2024

Do we need wildcards or existentials to typecheck this testcase (variant of your first testcase)

object existential {
  case class A()
  case class B()

  sealed abstract class AnyFoo
  case class Foo[T](x: T) extends AnyFoo

  val a: AnyFoo = Foo(A())
  val b: AnyFoo = Foo(B())

  val list0: List[AnyFoo] = List(a, b)
}

I wonder if the modifications made by @OlivierBlanvillain in the branch https://github.com/OlivierBlanvillain/stainless/tree/cats are enough

from stainless.

romac avatar romac commented on May 12, 2024

No, we don't them for such a variant. But it too fails with a type error as well on master. It also fails to verify on Olivier's branch (I don't have the output on hand right now but I'll post it later). And as far as I can tell, none of the changes in that branch should affect whether such code can be extracted or not.

from stainless.

jad-hamza avatar jad-hamza commented on May 12, 2024

This fails as well:

object Existential {
  case class A()

  sealed abstract class AnyFoo
  case class Foo[T](x: T) extends AnyFoo

  val a: AnyFoo = Foo(A())
}

from stainless.

jad-hamza avatar jad-hamza commented on May 12, 2024

I looked at the encoding, and I see that Foo has type: (Type, Object) => Object.
Then the issue happens when Foo is called: Foo(Adt(1072, Nil()), A()) is of type untyped
Apparently, the type of A() is not a subtype of Object (the inox function isSubtypeOf from TypeOps returns false).

@samarion Should isSubtypeOf return true in that case?

from stainless.

samarion avatar samarion commented on May 12, 2024

Hi, sorry for not helping much with the debugging, I haven't had time to actually run the examples and see what's going on.

@jad-hamza: in your example, isSubtypeOf is doing the right thing. The class A is specialized to an ADT because it fits into the fragment we know how to convert to ADTs. It therefore lives in a separate domain as the Object hierarchy.

This is an issue with specialized type boxing. It seems that boxing is not being performed for ClassConstructor arguments. To fix this, you can change the argument computation at

case s.ClassConstructor(ct, args) =>
val fd = classConstructors(ct.id)
t.FunctionInvocation(fd.id, Seq(), ct.tps.map(encodeType) ++ args.map(transform))

to something resembling
val newArgs = (fd.params zip args).map { case (vd, arg) =>
unifyTypes(transform(arg), transform(arg.getType), fdScope.transform(vd.tpe))
} ++ tps.map(encodeType)

This should hopefully fix the issue in your example. I'm not sure about the initial issue, I'll need to take a closer look once I have some time.

from stainless.

romac avatar romac commented on May 12, 2024

from stainless.

samarion avatar samarion commented on May 12, 2024

Fixed by #78

from stainless.

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.