mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Constants
This commit is contained in:
parent
fe8eb38d89
commit
03deec23c3
3 changed files with 8 additions and 16 deletions
|
@ -10,6 +10,9 @@ use roc_types::types::AliasKind;
|
||||||
|
|
||||||
pub use roc_exhaustive::Context as ExhaustiveContext;
|
pub use roc_exhaustive::Context as ExhaustiveContext;
|
||||||
|
|
||||||
|
pub const GUARD_CTOR: &'static str = "#Guard";
|
||||||
|
pub const NONEXHAUSIVE_CTOR: &'static str = "#Open";
|
||||||
|
|
||||||
pub fn check(
|
pub fn check(
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
sketched_rows: SketchedRows,
|
sketched_rows: SketchedRows,
|
||||||
|
@ -215,7 +218,7 @@ pub fn sketch_rows(target_var: Variable, region: Region, patterns: &[WhenBranch]
|
||||||
render_as: RenderAs::Guard,
|
render_as: RenderAs::Guard,
|
||||||
alternatives: vec![Ctor {
|
alternatives: vec![Ctor {
|
||||||
tag_id,
|
tag_id,
|
||||||
name: TagName::Global("#Guard".into()),
|
name: TagName::Global(GUARD_CTOR.into()),
|
||||||
arity: 2,
|
arity: 2,
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
@ -298,7 +301,7 @@ fn convert_tag(subs: &Subs, whole_var: Variable, this_tag: &TagName) -> (Union,
|
||||||
// be matched unless there's an `Anything` pattern.
|
// be matched unless there's an `Anything` pattern.
|
||||||
let opt_openness_tag = match subs.get_content_without_compacting(ext) {
|
let opt_openness_tag = match subs.get_content_without_compacting(ext) {
|
||||||
FlexVar(_) | RigidVar(_) => {
|
FlexVar(_) | RigidVar(_) => {
|
||||||
let openness_tag = TagName::Global("#Open".into());
|
let openness_tag = TagName::Global(NONEXHAUSIVE_CTOR.into());
|
||||||
num_tags += 1;
|
num_tags += 1;
|
||||||
Some((openness_tag, &[] as _))
|
Some((openness_tag, &[] as _))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2118,18 +2118,6 @@ impl Content {
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unroll_structural_alias<'a>(&'a self, subs: &'a Subs) -> &'a Self {
|
|
||||||
let mut result = self;
|
|
||||||
loop {
|
|
||||||
match result {
|
|
||||||
Self::Alias(_, _, real_var, AliasKind::Structural) => {
|
|
||||||
result = subs.get_content_without_compacting(*real_var)
|
|
||||||
}
|
|
||||||
_ => return result,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
|
|
@ -3632,6 +3632,7 @@ fn pattern_to_doc_help<'b>(
|
||||||
pattern: roc_exhaustive::Pattern,
|
pattern: roc_exhaustive::Pattern,
|
||||||
in_type_param: bool,
|
in_type_param: bool,
|
||||||
) -> RocDocBuilder<'b> {
|
) -> RocDocBuilder<'b> {
|
||||||
|
use roc_can::exhaustive::{GUARD_CTOR, NONEXHAUSIVE_CTOR};
|
||||||
use roc_exhaustive::Literal::*;
|
use roc_exhaustive::Literal::*;
|
||||||
use roc_exhaustive::Pattern::*;
|
use roc_exhaustive::Pattern::*;
|
||||||
use roc_exhaustive::RenderAs;
|
use roc_exhaustive::RenderAs;
|
||||||
|
@ -3654,7 +3655,7 @@ fn pattern_to_doc_help<'b>(
|
||||||
// #Guard <fake-condition-tag> <unexhausted-pattern>
|
// #Guard <fake-condition-tag> <unexhausted-pattern>
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
union.alternatives[tag_id.0 as usize].name,
|
union.alternatives[tag_id.0 as usize].name,
|
||||||
TagName::Global("#Guard".into())
|
TagName::Global(GUARD_CTOR.into())
|
||||||
);
|
);
|
||||||
debug_assert!(args.len() == 2);
|
debug_assert!(args.len() == 2);
|
||||||
let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param);
|
let tag = pattern_to_doc_help(alloc, args[1].clone(), in_type_param);
|
||||||
|
@ -3693,7 +3694,7 @@ fn pattern_to_doc_help<'b>(
|
||||||
RenderAs::Tag | RenderAs::Opaque => {
|
RenderAs::Tag | RenderAs::Opaque => {
|
||||||
let tag = &union.alternatives[tag_id.0 as usize];
|
let tag = &union.alternatives[tag_id.0 as usize];
|
||||||
match &tag.name {
|
match &tag.name {
|
||||||
TagName::Global(name) if name.as_str() == "#Open" => {
|
TagName::Global(name) if name.as_str() == NONEXHAUSIVE_CTOR => {
|
||||||
return pattern_to_doc_help(
|
return pattern_to_doc_help(
|
||||||
alloc,
|
alloc,
|
||||||
roc_exhaustive::Pattern::Anything,
|
roc_exhaustive::Pattern::Anything,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue