E4173

E4173#

Compiler diagnostic name: invalid_value_type_attr.

Invalid #valtype declaration.

#valtype asks the compiler to represent a type as a value type. Not every type shape can be represented this way. The compiler rejects declarations that would require boxed or runtime-object storage, such as a type parameter field, an object field, a mutable field, too many fields, or a nested value type field.

Erroneous example#

#valtype
struct Box[T] {
  value : T
}

The field value has type T, a type parameter. A value type must have a concrete supported layout, so this generic field is rejected.

Suggestion#

Use concrete scalar fields for the value type, or remove #valtype if the type needs a generic or boxed layout.

#valtype
struct Point {
  x : Int
  y : Int
}