Skip to content

Commit

Permalink
Merge branch 'master' into josh/serde
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty authored Dec 1, 2024
2 parents 8bcd7e7 + 6d9065b commit 712e825
Show file tree
Hide file tree
Showing 27 changed files with 753 additions and 102 deletions.
2 changes: 1 addition & 1 deletion sway-ast/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ impl Spanned for PathTypeSegment {
#[derive(Clone, Debug, Serialize)]
pub struct QualifiedPathRoot {
pub ty: Box<Ty>,
pub as_trait: Option<(AsToken, Box<PathType>)>,
pub as_trait: (AsToken, Box<PathType>),
}
1 change: 1 addition & 0 deletions sway-core/src/language/parsed/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ impl PartialEqWithEngines for IntrinsicFunctionExpression {
pub struct WhileLoopExpression {
pub condition: Box<Expression>,
pub body: CodeBlock,
pub is_desugared_for_loop: bool,
}

impl EqWithEngines for WhileLoopExpression {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,18 @@ impl ty::TyExpression {
arguments,
span,
),
ExpressionKind::WhileLoop(WhileLoopExpression { condition, body }) => {
Self::type_check_while_loop(handler, ctx.by_ref(), condition, body, span)
}
ExpressionKind::WhileLoop(WhileLoopExpression {
condition,
body,
is_desugared_for_loop,
}) => Self::type_check_while_loop(
handler,
ctx.by_ref(),
condition,
body,
*is_desugared_for_loop,
span,
),
ExpressionKind::ForLoop(ForLoopExpression { desugared }) => {
Self::type_check_for_loop(handler, ctx.by_ref(), desugared)
}
Expand Down Expand Up @@ -2131,6 +2140,7 @@ impl ty::TyExpression {
mut ctx: TypeCheckContext,
condition: &Expression,
body: &CodeBlock,
is_desugared_for_loop: bool,
span: Span,
) -> Result<Self, ErrorEmitted> {
let type_engine = ctx.engines.te();
Expand All @@ -2144,11 +2154,17 @@ impl ty::TyExpression {
};

let unit_ty = type_engine.id_of_unit();
let mut ctx = ctx.with_type_annotation(unit_ty).with_help_text(
"A while loop's loop body cannot implicitly return a value. Try \
let mut ctx = ctx
.with_type_annotation(unit_ty)
.with_help_text(if is_desugared_for_loop {
"A for loop's loop body cannot implicitly return a value. Try \
assigning it to a mutable variable declared outside of the loop \
instead.",
);
instead."
} else {
"A while loop's loop body cannot implicitly return a value. Try \
assigning it to a mutable variable declared outside of the loop \
instead."
});
let typed_body = ty::TyCodeBlock::type_check(handler, ctx.by_ref(), body, false)?;

let exp = ty::TyExpression {
Expand Down
37 changes: 19 additions & 18 deletions sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ pub(crate) fn type_name_to_type_info_opt(name: &Ident) -> Option<TypeInfo> {
"str" => Some(TypeInfo::StringSlice),
"raw_ptr" => Some(TypeInfo::RawUntypedPtr),
"raw_slice" => Some(TypeInfo::RawUntypedSlice),
"Self" | "self" => Some(TypeInfo::new_self_type(name.span())),
"Self" => Some(TypeInfo::new_self_type(name.span())),
"Contract" => Some(TypeInfo::Contract),
_other => None,
}
Expand Down Expand Up @@ -2131,6 +2131,7 @@ fn expr_to_expression(
kind: ExpressionKind::WhileLoop(WhileLoopExpression {
condition: Box::new(expr_to_expression(context, handler, engines, *condition)?),
body: braced_code_block_contents_to_code_block(context, handler, engines, block)?,
is_desugared_for_loop: false,
}),
span,
},
Expand Down Expand Up @@ -3278,6 +3279,7 @@ fn for_expr_to_expression(
span: Span::dummy(),
}),
body: while_body,
is_desugared_for_loop: true,
}),
span: Span::dummy(),
}),
Expand Down Expand Up @@ -3333,22 +3335,18 @@ fn path_root_opt_to_bool_and_qualified_path_root(
close_angle_bracket_token: _,
}),
_,
)) => (
false,
if let Some((_, path_type)) = as_trait {
Some(QualifiedPathType {
ty: ty_to_type_argument(context, handler, engines, *ty)?,
as_trait: engines.te().insert(
engines,
path_type_to_type_info(context, handler, engines, *path_type.clone())?,
path_type.span().source_id(),
),
as_trait_span: path_type.span(),
})
} else {
None
},
),
)) => (false, {
let (_, path_type) = as_trait;
Some(QualifiedPathType {
ty: ty_to_type_argument(context, handler, engines, *ty)?,
as_trait: engines.te().insert(
engines,
path_type_to_type_info(context, handler, engines, *path_type.clone())?,
path_type.span().source_id(),
),
as_trait_span: path_type.span(),
})
}),
})
}

Expand Down Expand Up @@ -4598,7 +4596,10 @@ fn path_type_to_type_info(
}
}
None => {
if name.as_str() == "ContractCaller" {
if name.as_str() == "self" {
let error = ConvertParseTreeError::UnknownTypeNameSelf { span };
return Err(handler.emit_err(error.into()));
} else if name.as_str() == "ContractCaller" {
if root_opt.is_some() || !suffix.is_empty() {
let error = ConvertParseTreeError::FullySpecifiedTypesNotSupported { span };
return Err(handler.emit_err(error.into()));
Expand Down
3 changes: 3 additions & 0 deletions sway-error/src/convert_parse_tree_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub enum ConvertParseTreeError {
UnexpectedValueForCfgExperimental { span: Span },
#[error("Unexpected attribute value: \"{value}\" for attribute: \"cfg\"")]
InvalidCfgArg { span: Span, value: String },
#[error("Unknown type name \"self\". A self type with a similar name exists (notice the capitalization): `Self`")]
UnknownTypeNameSelf { span: Span },
}

impl Spanned for ConvertParseTreeError {
Expand Down Expand Up @@ -185,6 +187,7 @@ impl Spanned for ConvertParseTreeError {
ConvertParseTreeError::ExpectedCfgProgramTypeArgValue { span } => span.clone(),
ConvertParseTreeError::UnexpectedValueForCfgExperimental { span } => span.clone(),
ConvertParseTreeError::InvalidCfgArg { span, .. } => span.clone(),
ConvertParseTreeError::UnknownTypeNameSelf { span } => span.clone(),
}
}
}
2 changes: 1 addition & 1 deletion sway-lib-std/src/bytes.sw
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl Bytes {
/// assert(bytes.capacity() == first_cap + second_cap);
/// }
/// ```
pub fn append(ref mut self, ref mut other: self) {
pub fn append(ref mut self, ref mut other: Self) {
let other_len = other.len();
if other_len == 0 {
return
Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/benches/lsp_benchmarks/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn benchmarks(c: &mut Criterion) {
c.bench_function("document_symbol", |b| {
b.iter(|| {
session
.symbol_information(&uri)
.map(DocumentSymbolResponse::Flat)
.document_symbols(&uri)
.map(DocumentSymbolResponse::Nested)
})
});

Expand Down
Loading

0 comments on commit 712e825

Please sign in to comment.