mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
step 2
This commit is contained in:
parent
9906623e34
commit
c725c27c1b
1 changed files with 22 additions and 19 deletions
|
@ -162,19 +162,9 @@ impl Scope {
|
||||||
debug_assert!(opaque_ref.starts_with('@'));
|
debug_assert!(opaque_ref.starts_with('@'));
|
||||||
let opaque = opaque_ref[1..].into();
|
let opaque = opaque_ref[1..].into();
|
||||||
|
|
||||||
match self.idents.get_symbol_and_region(&opaque) {
|
match self.locals.has_in_scope(&opaque) {
|
||||||
// TODO: is it worth caching any of these results?
|
Some((ident_id, _)) => {
|
||||||
Some((symbol, decl_region)) => {
|
let symbol = Symbol::new(self.home, ident_id);
|
||||||
if symbol.module_id() != self.home {
|
|
||||||
// The reference is to an opaque type declared in another module - this is
|
|
||||||
// illegal, as opaque types can only be wrapped/unwrapped in the scope they're
|
|
||||||
// declared.
|
|
||||||
return Err(RuntimeError::OpaqueOutsideScope {
|
|
||||||
opaque,
|
|
||||||
referenced_region: lookup_region,
|
|
||||||
imported_region: decl_region,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
match self.aliases.get(&symbol) {
|
match self.aliases.get(&symbol) {
|
||||||
None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)),
|
None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)),
|
||||||
|
@ -191,7 +181,22 @@ impl Scope {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => Err(self.opaque_not_defined_error(opaque, lookup_region, None)),
|
None => {
|
||||||
|
for (import, _, decl_region) in self.imports.iter() {
|
||||||
|
if &opaque == import {
|
||||||
|
// The reference is to an opaque type declared in another module - this is
|
||||||
|
// illegal, as opaque types can only be wrapped/unwrapped in the scope they're
|
||||||
|
// declared.
|
||||||
|
return Err(RuntimeError::OpaqueOutsideScope {
|
||||||
|
opaque,
|
||||||
|
referenced_region: lookup_region,
|
||||||
|
imported_region: *decl_region,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(self.opaque_not_defined_error(opaque, lookup_region, None))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,10 +257,8 @@ impl Scope {
|
||||||
ident: &Ident,
|
ident: &Ident,
|
||||||
region: Region,
|
region: Region,
|
||||||
) -> Result<Symbol, (Region, Loc<Ident>)> {
|
) -> Result<Symbol, (Region, Loc<Ident>)> {
|
||||||
match self.idents.get_symbol_and_region(ident) {
|
match self.locals.has_in_scope(ident) {
|
||||||
Some((_, original_region)) => {
|
Some((_, original_region)) => {
|
||||||
assert!(self.locals.has_in_scope(ident).is_some());
|
|
||||||
|
|
||||||
let shadow = Loc {
|
let shadow = Loc {
|
||||||
value: ident.clone(),
|
value: ident.clone(),
|
||||||
region,
|
region,
|
||||||
|
@ -576,13 +579,13 @@ impl ScopedIdentIds {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_in_scope(&self, ident: &Ident) -> Option<IdentId> {
|
fn has_in_scope(&self, ident: &Ident) -> Option<(IdentId, Region)> {
|
||||||
self.ident_ids
|
self.ident_ids
|
||||||
.ident_strs()
|
.ident_strs()
|
||||||
.zip(self.in_scope.iter())
|
.zip(self.in_scope.iter())
|
||||||
.find_map(|((ident_id, string), keep)| {
|
.find_map(|((ident_id, string), keep)| {
|
||||||
if *keep && string == ident.as_str() {
|
if *keep && string == ident.as_str() {
|
||||||
Some(ident_id)
|
Some((ident_id, self.regions[ident_id.index()]))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue