Skip to content

Commit f2154a3

Browse files
committed
Implement DelineatedPathExpression AST resolve handling.
1 parent 4dc1d53 commit f2154a3

File tree

8 files changed

+340
-31
lines changed

8 files changed

+340
-31
lines changed

sway-core/src/language/parsed/declaration.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Declaration {
121121
}
122122
}
123123

124-
pub(crate) fn to_fn_ref(
124+
pub(crate) fn to_fn_decl(
125125
&self,
126126
handler: &Handler,
127127
engines: &Engines,
@@ -149,6 +149,34 @@ impl Declaration {
149149
}
150150
}
151151

152+
pub(crate) fn to_enum_decl(
153+
&self,
154+
handler: &Handler,
155+
engines: &Engines,
156+
) -> Result<ParsedDeclId<EnumDeclaration>, ErrorEmitted> {
157+
match self {
158+
Declaration::EnumDeclaration(decl_id) => Ok(*decl_id),
159+
decl => Err(handler.emit_err(CompileError::DeclIsNotAnEnum {
160+
actually: decl.friendly_type_name().to_string(),
161+
span: decl.span(engines),
162+
})),
163+
}
164+
}
165+
166+
pub(crate) fn to_const_decl(
167+
&self,
168+
handler: &Handler,
169+
engines: &Engines,
170+
) -> Result<ParsedDeclId<ConstantDeclaration>, ErrorEmitted> {
171+
match self {
172+
Declaration::ConstantDeclaration(decl_id) => Ok(*decl_id),
173+
decl => Err(handler.emit_err(CompileError::DeclIsNotAConstant {
174+
actually: decl.friendly_type_name().to_string(),
175+
span: decl.span(engines),
176+
})),
177+
}
178+
}
179+
152180
#[allow(unused)]
153181
pub(crate) fn visibility(&self, decl_engine: &ParsedDeclEngine) -> Visibility {
154182
match self {

sway-core/src/language/parsed/expression/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use method_name::MethodName;
2323
pub use scrutinee::*;
2424
use sway_ast::intrinsics::Intrinsic;
2525

26-
use super::{FunctionDeclaration, StructDeclaration};
26+
use super::{Declaration, FunctionDeclaration, StructDeclaration};
2727

2828
/// Represents a parsed, but not yet type checked, [Expression](https://en.wikipedia.org/wiki/Expression_(computer_science)).
2929
#[derive(Debug, Clone)]
@@ -295,6 +295,8 @@ impl PartialEqWithEngines for AmbiguousPathExpression {
295295
#[derive(Debug, Clone)]
296296
pub struct DelineatedPathExpression {
297297
pub call_path_binding: TypeBinding<QualifiedCallPath>,
298+
pub resolved_call_path_binding: Option<TypeBinding<ResolvedCallPath<Declaration>>>,
299+
298300
/// When args is equal to Option::None then it means that the
299301
/// [DelineatedPathExpression] was initialized from an expression
300302
/// that does not end with parenthesis.

sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl ty::TyExpression {
307307
ExpressionKind::DelineatedPath(delineated_path_expression) => {
308308
let DelineatedPathExpression {
309309
call_path_binding,
310+
resolved_call_path_binding: _,
310311
args,
311312
} = *delineated_path_expression.clone();
312313
Self::type_check_delineated_path(

sway-core/src/semantic_analysis/node_dependencies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ impl Dependencies {
634634
ExpressionKind::DelineatedPath(delineated_path_expression) => {
635635
let DelineatedPathExpression {
636636
call_path_binding,
637+
resolved_call_path_binding: _,
637638
args,
638639
} = &**delineated_path_expression;
639640
// It's either a module path which we can ignore, or an enum variant path, in which

sway-core/src/semantic_analysis/symbol_resolve.rs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
},
1616
CallPath, CallPathTree, ResolvedCallPath,
1717
},
18-
TraitConstraint, TypeArgument, TypeBinding, TypeParameter,
18+
TraitConstraint, TypeArgs, TypeArgument, TypeBinding, TypeParameter,
1919
};
2020

2121
use super::symbol_resolve_context::SymbolResolveContext;
@@ -495,14 +495,8 @@ impl ResolveSymbols for StructScrutineeField {
495495
}
496496

497497
impl ResolveSymbols for Expression {
498-
fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
499-
self.kind.resolve_symbols(handler, ctx);
500-
}
501-
}
502-
503-
impl ResolveSymbols for ExpressionKind {
504498
fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
505-
match self {
499+
match &mut self.kind {
506500
ExpressionKind::Error(_, _) => {}
507501
ExpressionKind::Literal(_) => {}
508502
ExpressionKind::AmbiguousPathExpression(_) => {}
@@ -603,8 +597,26 @@ impl ResolveSymbols for ExpressionKind {
603597
.for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref()));
604598
}
605599
ExpressionKind::Subfield(expr) => expr.prefix.resolve_symbols(handler, ctx),
606-
ExpressionKind::DelineatedPath(expr) => {
607-
expr.call_path_binding.resolve_symbols(handler, ctx)
600+
ExpressionKind::DelineatedPath(ref mut expr) => {
601+
expr.call_path_binding
602+
.resolve_symbols(handler, ctx.by_ref());
603+
604+
// let result =
605+
// expr.call_path_binding
606+
// .resolve_symbol(handler, ctx.by_ref(), self.span.clone());
607+
608+
// if let Ok(result) = result {
609+
// expr.resolved_call_path_binding = Some(TypeBinding::<
610+
// ResolvedCallPath<ParsedDeclId<StructDeclaration>>,
611+
// > {
612+
// inner: ResolvedCallPath {
613+
// decl: result,
614+
// unresolved_call_path: expr.call_path_binding.inner.clone(),
615+
// },
616+
// span: expr.call_path_binding.span.clone(),
617+
// type_arguments: expr.call_path_binding.type_arguments.clone(),
618+
// });
619+
// }
608620
}
609621
ExpressionKind::AbiCast(expr) => {
610622
expr.abi_name.resolve_symbols(handler, ctx.by_ref());
@@ -644,3 +656,16 @@ impl ResolveSymbols for ExpressionKind {
644656
}
645657
}
646658
}
659+
660+
impl<T> ResolveSymbols for TypeBinding<T> {
661+
fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
662+
match self.type_arguments {
663+
TypeArgs::Regular(ref mut args) => args
664+
.iter_mut()
665+
.for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref())),
666+
TypeArgs::Prefix(ref mut args) => args
667+
.iter_mut()
668+
.for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref())),
669+
}
670+
}
671+
}

sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,6 +2905,7 @@ fn path_expr_to_expression(
29052905
Expression {
29062906
kind: ExpressionKind::DelineatedPath(Box::new(DelineatedPathExpression {
29072907
call_path_binding,
2908+
resolved_call_path_binding: None,
29082909
args: None,
29092910
})),
29102911
span,

0 commit comments

Comments
 (0)