Skip to content

Commit 0d628e8

Browse files
committed
Added namespace support for type aliases
1 parent 8b4a419 commit 0d628e8

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Diff for: src/parser/parse_type_alias.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
ast::{Named, TypeAlias},
44
inflow::Inflow,
55
name::Name,
6+
parser::annotation::AnnotationKind,
67
token::{Token, TokenKind},
78
};
89

@@ -14,12 +15,14 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
1415
let source = self.source_here();
1516
assert!(self.input.advance().is_type_alias_keyword());
1617

18+
let mut namespace = None;
1719
let name = self.parse_identifier(Some("for alias name after 'typealias' keyword"))?;
1820
self.ignore_newlines();
1921

2022
#[allow(clippy::never_loop, clippy::match_single_binding)]
2123
for annotation in annotations {
2224
match annotation.kind {
25+
AnnotationKind::Namespace(new_namespace) => namespace = Some(new_namespace),
2326
_ => return Err(self.unexpected_annotation(&annotation, Some("for type alias"))),
2427
}
2528
}
@@ -29,7 +32,7 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
2932
let becomes_type = self.parse_type(None::<&str>, Some("for type alias"))?;
3033

3134
Ok(Named::<TypeAlias> {
32-
name: Name::plain(name),
35+
name: Name::new(namespace, name),
3336
value: TypeAlias {
3437
value: becomes_type,
3538
source,

Diff for: src/resolve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn resolve<'a>(
104104
});
105105

106106
for (alias_name, alias) in file.type_aliases.iter() {
107-
type_aliases.put_type_alias(alias_name.clone(), alias, alias.source)?;
107+
type_aliases.put_type_alias(&alias_name, alias, alias.source)?;
108108
}
109109
}
110110

Diff for: src/resolve/type_search_ctx.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,11 @@ impl<'a> TypeSearchCtx<'a> {
143143

144144
pub fn put_type_alias(
145145
&mut self,
146-
name: impl ToString,
146+
name: &Name,
147147
value: &'a ast::TypeAlias,
148148
source: Source,
149149
) -> Result<(), ResolveError> {
150-
eprintln!("warning: TypeSearchCtx::put_type_alias always puts at root");
151-
let resolved_name = ResolvedName::Project(name.to_string().into_boxed_str());
150+
let resolved_name = ResolvedName::new(&name);
152151

153152
if self
154153
.types

0 commit comments

Comments
 (0)