function overriding error
See original GitHub issueG’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:
- Created 2 years ago
- Reactions:6
- Comments:12 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I may need to use
Object.hasOwnPropertyinternally, as I might be using a null check. I’ll look into this as soon as possible.This code was intended to be used as an internal library, not as a public methods 😃