foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Delete does'nt work great with chisel mappings

Open YourGuyD3v opened this issue 1 year ago • 2 comments

Component

Chisel

Have you ensured that all of these are up to date?

  • [ ] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

forge 0.2.0 (2097194 2023-06-23T00:10:47.525915714Z)

What command(s) is the bug in?

No response

Operating System

Linux

Describe the bug

chisel output:

➜ mapping(address => address) public token2token;
➜ token2token[address(1)] = address(2);
➜ address(2)
Type: address
└ Data: 0x0000000000000000000000000000000000000002
➜ delete token2token[address(1)];
➜ address(2)
Type: address
└ Data: 0x0000000000000000000000000000000000000002
➜ 

Run this on Remix and the mapping will be deleted:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

contract MappingTest {

    mapping(address => address) public token2token;

    function setToken(address token, address token2) public {
        token2token[token] = token2;
    }

     function remove(address token) public {
        delete token2token[token];
    }

    function get(address token) public view returns (address) {
        return token2token[token];
    }
}

YourGuyD3v avatar Mar 05 '24 15:03 YourGuyD3v

I am having the same issue:

Foundry Version

forge 0.2.0 (3dfa43b 2024-03-05T00:16:33.810560000Z)

chisel does not correctly delete mappings.

IzuMan0x avatar Mar 06 '24 03:03 IzuMan0x

@YourGuyD3v the code provided by you behaves exactly how it should !

why would delete token2token[address(1)]; this line have any impact on address(2) ? address(2) is always going to print the below output :

address(2)
Type: address
└ Data: 0x0000000000000000000000000000000000000002

@YourGuyD3v & @IzuMan0x I guess you meant :

➜ mapping(address => address) public checkMe;
➜ checkMe[address(1)] = address(2);
➜ delete checkMe[address(1)]

if yes, just add ; to the end of delete checkMe[address(1)] and then try checkMe[address(1)]

JayeshShukla avatar May 08 '24 10:05 JayeshShukla

Hi @JayeshShukla, Thanks for advising the Chisel statement (By adding ; to it). The recommendation is working fine.

But if the other statements work fine without adding the semicolon, then why not DELETE ? We need the Foundry team's help in addressing this issue.

dhanesh24g avatar Jun 20 '24 06:06 dhanesh24g

Marking as duplicate of https://github.com/foundry-rs/foundry/issues/7193

zerosnacks avatar Jul 12 '24 09:07 zerosnacks