Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow static access to interface function selectors #3506

Closed
fulldecent opened this issue Feb 14, 2018 · 9 comments · Fixed by #8105
Closed

Allow static access to interface function selectors #3506

fulldecent opened this issue Feb 14, 2018 · 9 comments · Fixed by #8105
Assignees
Labels
language design :rage4: Any changes to the language, e.g. new features

Comments

@fulldecent
Copy link
Contributor

fulldecent commented Feb 14, 2018

Test cases

 //pragma solidity 0.6.0-develop;

interface I {
    function i() external;
}

abstract contract C {
    function c() virtual external;
}

contract TestCase {
    function f() external {
        I.i.selector; // <------------- this is currently an error but should not be
        C.c.selector;
    }
}

contract TestCase2 is I, C {
    function f() external {
        I.i.selector;
        C.c.selector;
    }
    function i() override external{}
    function c() override external{}
}

Actual outcome

TypeError: Member "i" not found or not visible after argument-dependent lookup in type(contract I). I.i.selector;

Expected outcome

No error.

Discussion

Also need to handle specifying the function where there is function overloading.

Reference: related to ethereum/EIPs#881

@fulldecent
Copy link
Contributor Author

Possibly related, or I can create a separate issue.

pragma solidity ^0.4.19;

contract TestCase {

    function bob() public pure {
        
    }
    
    function TestCase() public {
        this.bob.selector;
    }
}

The error is

Warning: "this" used in constructor.

Likewise, I do not think this should be a warning.

@chriseth
Copy link
Contributor

Yes, sounds useful.

@axic axic added the language design :rage4: Any changes to the language, e.g. new features label Jul 28, 2018
@Arachnid
Copy link

It'd also be useful to be able to access these fields in constant initialisers:

contract Test{
  function foo() { }
  bytes4 constant FOO_FUNCTION_ID = foo.selector;
}

@chriseth
Copy link
Contributor

The main complication for implementing this is that this is not compile-time constant (it returns the current address) and thus you have a compile-time constant expression that has a non-compile-time constant sub-expression...

@fulldecent
Copy link
Contributor Author

For a first step requesting just the feature from the original post. Can add constants as an separate issue. (Which I still support.)


Here is a a case found in the wild that shows the problem of not having this feature:

https://github.com/erasureprotocol/erasure-protocol/blob/master/contracts/posts/Post_Factory.sol#L11

    constructor(address instanceRegistry, address templateContract) public {
        // declare template in memory
        Post template;

        // set instance type
        bytes4 instanceType = bytes4(keccak256(bytes('Post')));
        // set initSelector
        bytes4 initSelector = template.initialize.selector;
        // initialize factory params
        Factory._initialize(instanceRegistry, templateContract, instanceType, initSelector);
    }

They create template just to use the selector.

@axic
Copy link
Member

axic commented Dec 2, 2019

We actually have this implemented for contracts, added probably some time last year.

@bshastry
Copy link
Contributor

bshastry commented Dec 2, 2019

Notes from stand up: @fulldecent will do some more testing and update on this

@fulldecent fulldecent changed the title Allow static access to contract & interface function selectors Allow static access to interface function selectors Dec 2, 2019
@fulldecent
Copy link
Contributor Author

Top comment updated, test case updated per discussion.

@chriseth
Copy link
Contributor

chriseth commented Dec 3, 2019

Since this seems to be non-breaking, I'll add it to 0.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language design :rage4: Any changes to the language, e.g. new features
Projects
None yet
6 participants