Explicitly disallow ability definitions in nested scopes

Abilities can only be defined on the toplevel of a module. There is a
technical reason to this, which is that during type solving we must
introduce all abilities at the very beginning, and we need to make sure
ranks are correct. But there is a practical reason as well, which is
that nested ability definitions don't seem to be very useful.

Note that specializations can be nested, and are allowed to be. Also, we
can revisit this in the future. I just don't want experiments to break
right now because someone uses an ability in a nested scope where we
don't expect.

Closes #2878
This commit is contained in:
Ayaz Hafiz 2022-04-18 18:04:46 -04:00
parent 340f6b7c88
commit f129777115
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 89 additions and 31 deletions

View file

@ -278,6 +278,12 @@ pub struct AbilityMember<'a> {
pub typ: Loc<TypeAnnotation<'a>>,
}
impl AbilityMember<'_> {
pub fn region(&self) -> Region {
Region::across_all([self.name.region, self.typ.region].iter())
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TypeDef<'a> {
/// A type alias. This is like a standalone annotation, except the pattern