Skip to content

Commit 7a1157b

Browse files
committed
Implement DelineatedPathExpression AST resolve handling.
1 parent f51d7ae commit 7a1157b

File tree

9 files changed

+341
-43
lines changed

9 files changed

+341
-43
lines changed

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

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

125-
pub(crate) fn to_fn_ref(
125+
pub(crate) fn to_fn_decl(
126126
&self,
127127
handler: &Handler,
128128
engines: &Engines,
@@ -166,6 +166,34 @@ impl Declaration {
166166
}
167167
}
168168

169+
pub(crate) fn to_enum_decl(
170+
&self,
171+
handler: &Handler,
172+
engines: &Engines,
173+
) -> Result<ParsedDeclId<EnumDeclaration>, ErrorEmitted> {
174+
match self {
175+
Declaration::EnumDeclaration(decl_id) => Ok(*decl_id),
176+
decl => Err(handler.emit_err(CompileError::DeclIsNotAnEnum {
177+
actually: decl.friendly_type_name().to_string(),
178+
span: decl.span(engines),
179+
})),
180+
}
181+
}
182+
183+
pub(crate) fn to_const_decl(
184+
&self,
185+
handler: &Handler,
186+
engines: &Engines,
187+
) -> Result<ParsedDeclId<ConstantDeclaration>, ErrorEmitted> {
188+
match self {
189+
Declaration::ConstantDeclaration(decl_id) => Ok(*decl_id),
190+
decl => Err(handler.emit_err(CompileError::DeclIsNotAConstant {
191+
actually: decl.friendly_type_name().to_string(),
192+
span: decl.span(engines),
193+
})),
194+
}
195+
}
196+
169197
#[allow(unused)]
170198
pub(crate) fn visibility(&self, decl_engine: &ParsedDeclEngine) -> Visibility {
171199
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
@@ -445,6 +445,7 @@ impl ty::TyExpression {
445445
ExpressionKind::DelineatedPath(delineated_path_expression) => {
446446
let DelineatedPathExpression {
447447
call_path_binding,
448+
resolved_call_path_binding: _,
448449
args,
449450
} = *delineated_path_expression.clone();
450451
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: 38 additions & 21 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,23 +495,14 @@ 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(_) => {}
509503
ExpressionKind::FunctionApplication(expr) => {
510-
let result = SymbolResolveTypeBinding::resolve_symbol(
511-
&mut expr.call_path_binding,
512-
&Handler::default(),
513-
ctx.by_ref(),
514-
);
504+
let result = expr.call_path_binding.resolve_symbol(handler, ctx.by_ref());
505+
515506
if let Ok(result) = result {
516507
expr.resolved_call_path_binding = Some(TypeBinding::<
517508
ResolvedCallPath<ParsedDeclId<FunctionDeclaration>>,
@@ -547,13 +538,11 @@ impl ResolveSymbols for ExpressionKind {
547538
.iter_mut()
548539
.for_each(|e| e.resolve_symbols(handler, ctx.by_ref())),
549540
ExpressionKind::Struct(expr) => {
550-
expr.call_path_binding
551-
.resolve_symbols(handler, ctx.by_ref());
552-
let result = SymbolResolveTypeBinding::resolve_symbol(
553-
&mut expr.call_path_binding,
554-
&Handler::default(),
555-
ctx.by_ref(),
556-
);
541+
// expr.call_path_binding
542+
// .resolve_symbols(handler, ctx.by_ref());
543+
544+
let result = expr.call_path_binding.resolve_symbol(handler, ctx.by_ref());
545+
557546
if let Ok(result) = result {
558547
expr.resolved_call_path_binding = Some(TypeBinding::<
559548
ResolvedCallPath<ParsedDeclId<StructDeclaration>>,
@@ -604,7 +593,22 @@ impl ResolveSymbols for ExpressionKind {
604593
}
605594
ExpressionKind::Subfield(expr) => expr.prefix.resolve_symbols(handler, ctx),
606595
ExpressionKind::DelineatedPath(expr) => {
607-
expr.call_path_binding.resolve_symbols(handler, ctx)
596+
let result =
597+
expr.call_path_binding
598+
.resolve_symbol(handler, ctx.by_ref(), self.span.clone());
599+
600+
if let Ok(_result) = result {
601+
// expr.resolved_call_path_binding = Some(TypeBinding::<
602+
// ResolvedCallPath<ParsedDeclId<StructDeclaration>>,
603+
// > {
604+
// inner: ResolvedCallPath {
605+
// decl: result,
606+
// unresolved_call_path: expr.call_path_binding.inner.clone(),
607+
// },
608+
// span: expr.call_path_binding.span.clone(),
609+
// type_arguments: expr.call_path_binding.type_arguments.clone(),
610+
// });
611+
}
608612
}
609613
ExpressionKind::AbiCast(expr) => {
610614
expr.abi_name.resolve_symbols(handler, ctx.by_ref());
@@ -644,3 +648,16 @@ impl ResolveSymbols for ExpressionKind {
644648
}
645649
}
646650
}
651+
652+
impl<T> ResolveSymbols for TypeBinding<T> {
653+
fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
654+
match self.type_arguments {
655+
TypeArgs::Regular(ref mut args) => args
656+
.iter_mut()
657+
.for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref())),
658+
TypeArgs::Prefix(ref mut args) => args
659+
.iter_mut()
660+
.for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref())),
661+
}
662+
}
663+
}

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
@@ -2903,6 +2903,7 @@ fn path_expr_to_expression(
29032903
Expression {
29042904
kind: ExpressionKind::DelineatedPath(Box::new(DelineatedPathExpression {
29052905
call_path_binding,
2906+
resolved_call_path_binding: None,
29062907
args: None,
29072908
})),
29082909
span,

0 commit comments

Comments
 (0)