Skip to content

Commit

Permalink
Remove panics
Browse files Browse the repository at this point in the history
  • Loading branch information
DeviousStoat committed Jun 23, 2024
1 parent f978801 commit 5cc82df
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions compiler-core/src/erlang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,24 @@ fn const_string_concatenate_argument<'a>(
match value {
Constant::String { value, .. } => docvec!['"', string_inner(value), "\"/utf8"],

Constant::Var { constructor: Some(constructor), .. } => {
match &constructor.variant {
ValueConstructorVariant::ModuleConstant { literal: Constant::String { value, ..}, .. } => docvec!['"', string_inner(value), "\"/utf8"],
ValueConstructorVariant::ModuleConstant { literal: concat_value @ Constant::StringConcatenation { .. }, .. } => docvec![const_inline(concat_value, env), "/binary"],
_ => panic!("Constant string concatenation argument can only be a string or const var at code generation time"),
}
}
Constant::Var {
constructor: Some(constructor),
..
} => match &constructor.variant {
ValueConstructorVariant::ModuleConstant {
literal: Constant::String { value, .. },
..
} => docvec!['"', string_inner(value), "\"/utf8"],
ValueConstructorVariant::ModuleConstant {
literal: concat_value @ Constant::StringConcatenation { .. },
..
} => docvec![const_inline(concat_value, env), "/binary"],
_ => const_inline(value, env),
},

Constant::StringConcatenation { .. } => docvec![const_inline(value, env), "/binary"],

_ => panic!("Constant string concatenation argument can only be a string or const var at code generation time"),
_ => const_inline(value, env),
}
}

Expand Down

0 comments on commit 5cc82df

Please sign in to comment.