question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

function overriding error

See original GitHub issue

G’day, mates!

While I’m testing Strings.sol library, I got an error with TypeError: uniqueNames[name_1].push is not a function.

contracts

library Strings {
    function toString(uint256 value) public pure returns (string memory) {
        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }
}

testing script

const { expect, assert } = require("chai");
const { ethers } = require("hardhat");

describe("Library Test", function () {

    let Test, test, owner, addr1;

    beforeEach(async function () {
        Test = await ethers.getContractFactory("Strings");
        [owner, addr1] = await ethers.getSigners();
        test = await Test.deploy();
    })

    it("Strings test", async function () {
        const t1 = await test.toString(123);                     //error point
        console.log(t1);
    });
});

I changed a function name from toString to toStrin just for testing. and it works. function toString(uint256 value) public

function toStrin(uint256 value) public
                             &
const t1 = await test.toStrin(123);

So I thought it’s because js has the function with the same name. But although I tried callStatic function to override the js function, it still didn’t work.

const t1 = await test.callStatic["toString(uint256)"](123);

repeatedly same error TypeError: uniqueNames[name_1].push is not a function.

But expectedly const t1 = await test.callStatic["toStrin(uint256)"](123); with function function toStrin(uint256 value) public worked.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, Apr 10, 2021

I may need to use Object.hasOwnProperty internally, as I might be using a null check. I’ll look into this as soon as possible.

2reactions
k06acommented, Jun 2, 2021

This code was intended to be used as an internal library, not as a public methods 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting method overriding error? - Stack Overflow
It is a compile-time error to attempt to override or hide a final method. You are trying to override final static void m...
Read more >
Method Overriding Error in C# - MSDN - Microsoft
It's not possible to override any method without specifying (1) the same method name, (2) the same parameter type(s) and the same returned...
Read more >
Exception Handling with Method Overriding in Java
An Exception is an unwanted or unexpected event, which occurs during the execution of a program i.e at run-time, that disrupts the normal...
Read more >
override specifier (since C++11) - cppreference.com
In a member function declaration or definition, override specifier ensures that the function is virtual and is overriding a virtual function ...
Read more >
C++ Function Overriding - Programiz
This is known as function overriding in C++. The function in derived class overrides the function in base class. Example 1: C++ Function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found