// TODO: check that flavor is readonly or mutable.
@Override
  public action to_value(action expression, origin the_origin) {
    if (constraints != null) {
      // We need to specially handled narrowed variables here
      // because the reference type is not narrowed.
      // Say the variable declaration is "string or null foo", and it's narrowed to string.
      // The is_reference_type(the_type) would return a union type, which is not what we want.
      action narrowed_action = can_narrow(expression, constraints);
      if (narrowed_action != null) {
        return narrowed_action;
      }
    }
    type the_type = expression.result().type_bound();
    if (common_types.is_reference_type(the_type)) {
      // TODO: check that flavor is readonly or mutable.
      type value_type = common_types.get_reference_parameter(the_type);
      // TODO: replace this with a promotion lookup.
      return promote(expression, value_type, the_origin);
    } else {
      return expression;
    }
  }
type the_type = expression.result().type_bound();
if (common_types.is_reference_type(the_type)) {
// TODO: check that flavor is readonly or mutable.
type value_type = common_types.get_reference_parameter(the_type);
// TODO: replace this with a promotion lookup.
// because the reference type is not narrowed.
// Say the variable declaration is "string or null foo", and it's narrowed to string.
// The is_reference_type(the_type) would return a union type, which is not what we want.
action narrowed_action = can_narrow(expression, constraints);
if (narrowed_action != null) {
return narrowed_action;
}
}
type the_type = expression.result().type_bound();
if (common_types.is_reference_type(the_type)) {
// TODO: check that flavor is readonly or mutable.
type value_type = common_types.get_reference_parameter(the_type);
// TODO: replace this with a promotion lookup.
return promote(expression, value_type, the_origin);
} else {
return expression;
}
}
@Override
public action to_value(action expression, origin the_origin) {
if (constraints != null) {
// We need to specially handled narrowed variables here
// because the reference type is not narrowed.
// Say the variable declaration is "string or null foo", and it's narrowed to string.
// The is_reference_type(the_type) would return a union type, which is not what we want.
action narrowed_action = can_narrow(expression, constraints);
if (narrowed_action != null) {
return narrowed_action;
}
}
type the_type = expression.result().type_bound();
if (common_types.is_reference_type(the_type)) {
// TODO: check that flavor is readonly or mutable.
type value_type = common_types.get_reference_parameter(the_type);
// TODO: replace this with a promotion lookup.
return promote(expression, value_type, the_origin);
} else {
return expression;
}
}