{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/solidity/issues/4531","repository_url":"https://api.github.com/repos/ethereum/solidity","labels_url":"https://api.github.com/repos/ethereum/solidity/issues/4531/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/solidity/issues/4531/comments","events_url":"https://api.github.com/repos/ethereum/solidity/issues/4531/events","html_url":"https://github.com/ethereum/solidity/issues/4531","id":342967663,"node_id":"MDU6SXNzdWUzNDI5Njc2NjM=","number":4531,"title":"Question: Can string be mapping key value?","user":{"login":"KenjiOhtsuka","id":1572810,"node_id":"MDQ6VXNlcjE1NzI4MTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1572810?v=4","gravatar_id":"","url":"https://api.github.com/users/KenjiOhtsuka","html_url":"https://github.com/KenjiOhtsuka","followers_url":"https://api.github.com/users/KenjiOhtsuka/followers","following_url":"https://api.github.com/users/KenjiOhtsuka/following{/other_user}","gists_url":"https://api.github.com/users/KenjiOhtsuka/gists{/gist_id}","starred_url":"https://api.github.com/users/KenjiOhtsuka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KenjiOhtsuka/subscriptions","organizations_url":"https://api.github.com/users/KenjiOhtsuka/orgs","repos_url":"https://api.github.com/users/KenjiOhtsuka/repos","events_url":"https://api.github.com/users/KenjiOhtsuka/events{/privacy}","received_events_url":"https://api.github.com/users/KenjiOhtsuka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-20T04:15:30Z","updated_at":"2018-07-20T07:48:15Z","closed_at":null,"author_association":"NONE","body":"According to [Types page](https://solidity.readthedocs.io/en/latest/types.html),\r\n\r\n> Mapping types are declared as `mapping(_KeyType => _ValueType)`. Here `_KeyType` can be almost any type except for a mapping, a dynamically sized array, a contract, an enum and a struct. `_ValueType` can actually be any type, including mappings.\r\n\r\n`string` seems not to be able to be mapping key.\r\n\r\nBut, some codes uses `string` as key.\r\n\r\n* https://www.toshblocks.com/solidity/general-value-data-types-solidity/\r\n    `mapping (string => uint) public balances;`\r\n* [integer_overflow_mapping_strkey.sol](https://github.com/trailofbits/manticore/blob/b184f4e91612a83d3bac294d2f5bf32ec2594958/tests/binaries/benchmark/integer_overflow_mapping_strkey.sol)\r\n\r\nAnd in my environment, the following code worked.\r\n\r\n```sollidity\r\npragma solidity ^0.4.24;\r\n\r\ncontract Proof {\r\n    struct FileDetails {\r\n        uint timestamp;\r\n        string owner;\r\n    }\r\n    mapping (string => FileDetails) files;\r\n    event logFileAddedStatus(\r\n        bool status, uint timestamp, string owner, string fileHash);\r\n    function set(string owner, string fileHash) {\r\n        if (files[fileHash].timestamp == 0) {\r\n            files[fileHash] = FileDetails(block.timestamp, owner);\r\n            logFileAddedStatus(true, block.timestamp, owner, fileHash);\r\n        } else {\r\n            logFileAddedStatus(false, block.timestamp, owner, fileHash);\r\n        }\r\n    }\r\n\r\n    function get(string fileHash) returns (uint timestamp, string owner) {\r\n        return (files[fileHash].timestamp, files[fileHash].owner);\r\n    }\r\n}\r\n```\r\n\r\nActually, can `string` be mapping key value?\r\n\r\nIn [Types page](https://solidity.readthedocs.io/en/latest/types.html) says,\r\n\r\n> Mappings can be seen as hash tables which are virtually initialized such that every possible key exists and is mapped to a value whose byte-representation is all zeros\r\n\r\nHow does string virtual initialization work?"},"comment":{"url":"https://api.github.com/repos/ethereum/solidity/issues/comments/406517716","html_url":"https://github.com/ethereum/solidity/issues/4531#issuecomment-406517716","issue_url":"https://api.github.com/repos/ethereum/solidity/issues/4531","id":406517716,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjUxNzcxNg==","user":{"login":"chriseth","id":9073706,"node_id":"MDQ6VXNlcjkwNzM3MDY=","avatar_url":"https://avatars2.githubusercontent.com/u/9073706?v=4","gravatar_id":"","url":"https://api.github.com/users/chriseth","html_url":"https://github.com/chriseth","followers_url":"https://api.github.com/users/chriseth/followers","following_url":"https://api.github.com/users/chriseth/following{/other_user}","gists_url":"https://api.github.com/users/chriseth/gists{/gist_id}","starred_url":"https://api.github.com/users/chriseth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriseth/subscriptions","organizations_url":"https://api.github.com/users/chriseth/orgs","repos_url":"https://api.github.com/users/chriseth/repos","events_url":"https://api.github.com/users/chriseth/events{/privacy}","received_events_url":"https://api.github.com/users/chriseth/received_events","type":"User","site_admin":false},"created_at":"2018-07-20T07:48:15Z","updated_at":"2018-07-20T07:48:15Z","author_association":"CONTRIBUTOR","body":"Created an issue to fix the documentation: https://github.com/ethereum/solidity/issues/4532"}}
{"actor":{"display_login":"chriseth"}}