stainless icon indicating copy to clipboard operation
stainless copied to clipboard

Cannot instantiate a non-mutable type parameter T in Option[T]

Open mwookawa opened this issue 4 years ago • 5 comments

Given

@mutable trait B {}

case class A (var foo: Int) extends B { val baz: Int = foo }


object D {
  def bar(a: Option[B] = None()) { if(a.isDefined) {} } 

Stainless tosses out the exception 2020.10.01 12:39:20 INFO inox.package$FatalError: Cannot instantiate a non-mutable type parameter T in @library

Because I can't annotate Option[T] as Option[@mutable T], there's no obvious way to fix this. Are mutable classes in option types just not supported?

mwookawa avatar Oct 01 '20 16:10 mwookawa

Right, perhaps we should change it in the library. You can try adding the annotation here https://github.com/epfl-lara/stainless/blob/master/frontends/library/stainless/lang/Option.scala or making your own copy of this file with @mutable T.

Edit: Actually it might be best to have two different types, so that by default the pure Option can be assumed to be non mutable by Stainless (which makes some transformations simpler).

jad-hamza avatar Oct 03 '20 07:10 jad-hamza

i tried the former, annotating the type variable, but got the same error message. thoughts?

mwookawa avatar Oct 05 '20 13:10 mwookawa

That's strange, is it maybe an issue with sbt caching? Can you try to define MyOption as a copy in your own file to see if it works?

jad-hamza avatar Oct 06 '20 15:10 jad-hamza

I think it's doing this with bloop and sbt. (i'm finally running on macos). i'll try pasting

mwookawa avatar Oct 06 '20 16:10 mwookawa

sorry for the delay. we've moved temporarily to a situation where this error hasn't yet popped up.

mwookawa avatar Oct 08 '20 18:10 mwookawa