Merge pull request #1591 from rtfeldman/single-quote-literal

Single Quote literal
This commit is contained in:
Richard Feldman 2022-02-26 23:27:46 -05:00 committed by GitHub
commit d3acf34415
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 404 additions and 18 deletions

View file

@ -2040,8 +2040,11 @@ fn pattern_to_when<'a>(
}
UnwrappedOpaque { .. } => todo_opaques!(),
IntLiteral(..) | NumLiteral(..) | FloatLiteral(..) | StrLiteral(_) => {
IntLiteral(..)
| NumLiteral(..)
| FloatLiteral(..)
| StrLiteral(..)
| roc_can::pattern::Pattern::SingleQuote(..) => {
// These patters are refutable, and thus should never occur outside a `when` expression
// They should have been replaced with `UnsupportedPattern` during canonicalization
unreachable!("refutable pattern {:?} where irrefutable pattern is expected. This should never happen!", pattern.value)
@ -3147,6 +3150,13 @@ pub fn with_hole<'a>(
hole,
),
SingleQuote(character) => Stmt::Let(
assigned,
Expr::Literal(Literal::Int(character as _)),
Layout::int_width(IntWidth::I32),
hole,
),
Num(var, num_str, num, _bound) => {
// first figure out what kind of number this is
match num_argument_to_int_or_float(env.subs, env.target_info, var, false) {
@ -7746,6 +7756,7 @@ fn from_can_pattern_help<'a>(
}
}
StrLiteral(v) => Ok(Pattern::StrLiteral(v.clone())),
SingleQuote(c) => Ok(Pattern::IntLiteral(*c as _, IntWidth::I32)),
Shadowed(region, ident, _new_symbol) => Err(RuntimeError::Shadowing {
original_region: *region,
shadow: ident.clone(),