Skip to content

How to initialize a variable of type choice #6861

@istmarc

Description

@istmarc

Description of the bug:

Hello,

The following code doesn't work and I cannot initialize a variable of type choice:

choice VehicleType {
   Bike,
   Car,
   Bus
}
var my_vehicle : VehicleType = VehicleType.Car;

What did you do, or what's a simple way to reproduce the bug?

Compile the following code with the latest toolchain:

import Core library "io";
import Core library "range";

fn Run() -> i32 {
   choice VehicleType {
      Bike,
      Car,
      Bus
   }
   var my_vehicle : VehicleType = VehicleType.Car;
  return 0;
}

What did you expect to happen?

Initialize a variable of type choice / sum type.

What actually happened?

I get the following errors:

error: cannot copy value of type `VehicleType`
<09>var my_vehicle : VehicleType = VehicleType.Car;
                                   ^~~~~~~~~~~~~~~
note: type `VehicleType` does not implement interface `Core.Copy`
<09>var my_vehicle : VehicleType = VehicleType.Car;

Any other information, logs, or outputs that you want to share?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions