Compiler message change request

Just spent 10 minutes wondering what could go wrong. Well, say I have a module that looks like this:

module M {
  struct T<A> {} 
  public fun test<A>() {
    let _ = T<A> {};
  }
}

And I mean this module as used with copyable types (but I have not though it through). The error I get while trying to compile is Cannot ignore resource values. The value must be used. My reaction is: “WTF, why resources if I try to use it with copyable type?!” and I meant (in my head) that this currently can only be copyable. And at this moment I do not even think that there can be a resource!

I dunno if it is possible to separate this case from case where <T: resource> constraint is used but if this were possible, could you warn user that he maybe should put constraint and limit use to copyable?

It could save a lot of time debugging. :laughing: Because I met this error in more complex scenario where I have bunch of modules none of which uses resources in type parameters and it made me think that everything is completely wrong.

Another question just came to mind. Will it ever be possible to use resource type in struct generic (without actually placing resource into this struct) and expect this type to still be copyable?

I think I know the answer. But the reason is what I am curious about. :upside_down_face:

module M {
  // or maybe even add :resource constraint!
  struct T1<R> {} 
  resource struct K {}

  public fun test() {
    // obviously value is not a resource, only by its type
    let _ = T1<K>{}; 
  }
}

When you write struct T<A>, it is shorthand for struct T<A: all>. The type constraint all can be bound to both a resource or copyable type, which is why you’re getting the error. Agreed that this is confusing and that it would be good to suggest the resolution of using : copyable.

Another question just came to mind. Will it ever be possible to use resource type in struct generic (without actually placing resource into this struct) and expect this type to still be copyable?
I think I know the answer. But the reason is what I am curious about. :upside_down_face:

No, it will not be possible. I understand what your T1<K> example is getting at-- “there’s no resource data value inside T1, so why can’t I discard or copy it”? The reason at that the type system can’t (and shouldn’t) distinguish between “phantom” resources like T1<K> and “real” resources like T1<Coin>. When a type is declared as a resource, it always gets the resource safety protections.