diff --git a/crates/sema/src/ast_passes.rs b/crates/sema/src/ast_passes.rs index 9bd962fc..84082c41 100644 --- a/crates/sema/src/ast_passes.rs +++ b/crates/sema/src/ast_passes.rs @@ -92,6 +92,20 @@ impl<'sess> AstValidator<'sess, '_> { .emit(); } } + + fn check_var_for_named_return_params(&self, var: &ast::VariableDefinition<'_>) { + if let ast::TypeKind::Function(f) = &var.ty.kind { + for param in f.returns.iter() { + if let Some(param_name) = param.name { + self.dcx() + .err("return parameters in function types may not be named") + .span(param.span) + .help(format!("remove `{param_name}`")) + .emit(); + } + } + } + } } impl<'ast> Visit<'ast> for AstValidator<'_, 'ast> { @@ -209,6 +223,14 @@ impl<'ast> Visit<'ast> for AstValidator<'_, 'ast> { .emit(); } } + ast::StmtKind::DeclSingle(var) => { + self.check_var_for_named_return_params(var); + } + ast::StmtKind::DeclMulti(vars, _) => { + for var in vars.iter().flatten() { + self.check_var_for_named_return_params(var); + } + } _ => {} } diff --git a/tests/ui/resolve/func_ty_named_params.sol b/tests/ui/resolve/func_ty_named_params.sol new file mode 100644 index 00000000..565a54ea --- /dev/null +++ b/tests/ui/resolve/func_ty_named_params.sol @@ -0,0 +1,11 @@ +contract A { + constructor() { + function(uint256) view returns (uint256) a; + + function(uint256) view returns (uint256 j) c; //~ERROR: return parameters in function types may not be named + //~^WARN: named function type parameters are deprecated + + function(uint256 k) view returns (uint256) d; + //~^WARN: named function type parameters are deprecated + } +} diff --git a/tests/ui/resolve/func_ty_named_params.stderr b/tests/ui/resolve/func_ty_named_params.stderr new file mode 100644 index 00000000..bbe864a3 --- /dev/null +++ b/tests/ui/resolve/func_ty_named_params.stderr @@ -0,0 +1,24 @@ +warning[6162]: named function type parameters are deprecated + --> ROOT/tests/ui/resolve/func_ty_named_params.sol:LL:CC + | +LL | function(uint256) view returns (uint256 j) c; + | - + | + +warning[6162]: named function type parameters are deprecated + --> ROOT/tests/ui/resolve/func_ty_named_params.sol:LL:CC + | +LL | function(uint256 k) view returns (uint256) d; + | - + | + +error: return parameters in function types may not be named + --> ROOT/tests/ui/resolve/func_ty_named_params.sol:LL:CC + | +LL | function(uint256) view returns (uint256 j) c; + | ^^^^^^^^^ + | + = help: remove `j` + +error: aborting due to 1 previous error; 2 warnings emitted +