ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.28k stars 5.77k forks source link

Incorrect byte location (src) of the `FunctionTypeName` AST node #13281

Closed michprev closed 1 year ago

michprev commented 2 years ago

Description

Byte location (src) of the FunctionTypeName AST node is incorrect when combined with the VariableDeclaration parent node.

Environment

Steps to Reproduce

Please consider the following example (taken from https://docs.soliditylang.org/en/v0.8.15/assembly.html#access-to-external-variables-functions-and-libraries):

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.10 <0.9.0;

contract C {
    // Assigns a new selector and address to the return variable @fun                           The problem is here: ▼▼▼
    function combineToFunctionPointer(address newAddress, uint newSelector) public pure returns (function() external fun) {
        assembly {
            fun.selector := newSelector
            fun.address  := newAddress
        }
    }
}

And the relevant part of the generated AST (return parameters of the combineToFunctionPointer function):

"returnParameters":{
   "id":11,
   "nodeType":"ParameterList",
   "parameters":[
      {
         "constant":false,
         "id":10,
         "mutability":"mutable",
         "name":"fun",
         "nameLocation":"270:3:0",
         "nodeType":"VariableDeclaration",
         "scope":14,
         "src":"250:23:0",
         "stateVariable":false,
         "storageLocation":"default",
         "typeDescriptions":{
            "typeIdentifier":"t_function_external_nonpayable$__$returns$__$",
            "typeString":"function () external"
         },
         "typeName":{
            "id":9,
            "nodeType":"FunctionTypeName",
            "parameterTypes":{
               "id":7,
               "nodeType":"ParameterList",
               "parameters":[

               ],
               "src":"258:2:0"
            },
            "returnParameterTypes":{
               "id":8,
               "nodeType":"ParameterList",
               "parameters":[

               ],
               "src":"270:0:0"
            },
            "src":"250:23:0",
            "stateMutability":"nonpayable",
            "typeDescriptions":{
               "typeIdentifier":"t_function_external_nonpayable$__$returns$__$",
               "typeString":"function () external"
            },
            "visibility":"external"
         },
         "visibility":"internal"
      }
   ],

Current behavior:

src of the FunctionTypeName node (AST ID 9) is 250:23:0.

Expected behavior:

src of the FunctionTypeName node (AST ID 9) should be 250:19:0.

github-actions[bot] commented 1 year ago

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.

github-actions[bot] commented 1 year ago

Hi everyone! This issue has been automatically closed due to inactivity. If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen. However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.