diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 90a4f4cd7..eadcdbbaf 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -332,7 +332,11 @@ vector AsmAnalyzer::operator()(FunctionCall const& _funCall) for (size_t i = _funCall.arguments.size(); i > 0; i--) { Expression const& arg = _funCall.arguments[i - 1]; - if (auto literalArgumentKind = literalArguments ? literalArguments->at(i - 1) : std::nullopt) + if ( + auto literalArgumentKind = (literalArguments && i <= literalArguments->size()) ? + literalArguments->at(i - 1) : + std::nullopt + ) { if (!holds_alternative(arg)) m_errorReporter.typeError( diff --git a/test/libyul/yulSyntaxTests/builtin_function_literal.yul b/test/libyul/yulSyntaxTests/builtin_function_literal.yul new file mode 100644 index 000000000..81d2c1ed5 --- /dev/null +++ b/test/libyul/yulSyntaxTests/builtin_function_literal.yul @@ -0,0 +1,7 @@ +{ + datasize(x,1) +} +// ---- +// TypeError 7000: (4-12): Function expects 1 arguments but got 2. +// TypeError 9114: (4-12): Function expects direct literals as arguments. +// DeclarationError 8198: (13-14): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/function_literal.yul b/test/libyul/yulSyntaxTests/function_literal.yul new file mode 100644 index 000000000..b9652e354 --- /dev/null +++ b/test/libyul/yulSyntaxTests/function_literal.yul @@ -0,0 +1,6 @@ +{ + function f(a,b) {} + f(x,1) +} +// ---- +// DeclarationError 8198: (27-28): Identifier not found. diff --git a/test/libyul/yulSyntaxTests/function_literal_valid.yul b/test/libyul/yulSyntaxTests/function_literal_valid.yul new file mode 100644 index 000000000..b36928ad4 --- /dev/null +++ b/test/libyul/yulSyntaxTests/function_literal_valid.yul @@ -0,0 +1,6 @@ +{ + let x + function f(a,b) {} + f(x,1) +} +// ----