{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/solidity/issues/4103","repository_url":"https://api.github.com/repos/ethereum/solidity","labels_url":"https://api.github.com/repos/ethereum/solidity/issues/4103/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/solidity/issues/4103/comments","events_url":"https://api.github.com/repos/ethereum/solidity/issues/4103/events","html_url":"https://github.com/ethereum/solidity/issues/4103","id":321521941,"number":4103,"title":"Consider showing a warning when pragma & compiler versions are different","user":{"login":"alex-ppg","id":31933616,"avatar_url":"https://avatars3.githubusercontent.com/u/31933616?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-ppg","html_url":"https://github.com/alex-ppg","followers_url":"https://api.github.com/users/alex-ppg/followers","following_url":"https://api.github.com/users/alex-ppg/following{/other_user}","gists_url":"https://api.github.com/users/alex-ppg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-ppg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-ppg/subscriptions","organizations_url":"https://api.github.com/users/alex-ppg/orgs","repos_url":"https://api.github.com/users/alex-ppg/repos","events_url":"https://api.github.com/users/alex-ppg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-ppg/received_events","type":"User","site_admin":false},"labels":[{"id":275027668,"url":"https://api.github.com/repos/ethereum/solidity/labels/documentation","name":"documentation","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-05-09T10:49:03Z","updated_at":"2018-05-16T12:06:33Z","closed_at":null,"author_association":"NONE","body":"Using a different compiler version than the one specified with the `pragma` keyword can result in unintended behavior as the `pragma` keyword is ambiguous. As such, it would be best to show a **warning** for those who want to heed it and ensure backward compatibility. An example scenario can be found below:\r\n- Which version of Solidity are you using?\r\nThe compiler is running Solidity version 0.4.23.\r\n- What was the source code?\r\n```\r\npragma solidity ^0.4.1;\r\n\r\ncontract StringTest {\r\n    event A();\r\n    \r\n    constructor() public {\r\n        emit A();\r\n    }\r\n}\r\n```\r\n- Which platform are you running on?\r\nIrrelevant.\r\n- How to reproduce the issue?\r\nAttempt to compile the above contract with Solidity 0.4.1.\r\nProceed to compile the above contract with Solidity 0.4.23.\r\n- What was the result of the issue?\r\nThe compiler failed to compile the code with Solidity 0.4.1 but succeeded with version 0.4.23.\r\n- What is the expected behavior?\r\nThe compiler, when writing code using version 0.4.23, should show a **warning** suggesting that you alter your pragma version to match your compiler version.\r\n\r\nThis can be done simply by checking if the `^` keyword exists in `pragma` and if it does check whether the version is lower than the compiler. Showing an ***error*** instead of a ***warning*** would require that the compiler has knowledge of previous versions and available features which would unnecessarily increase its complexity."},"comment":{"url":"https://api.github.com/repos/ethereum/solidity/issues/comments/389495110","html_url":"https://github.com/ethereum/solidity/issues/4103#issuecomment-389495110","issue_url":"https://api.github.com/repos/ethereum/solidity/issues/4103","id":389495110,"user":{"login":"alex-ppg","id":31933616,"avatar_url":"https://avatars3.githubusercontent.com/u/31933616?v=4","gravatar_id":"","url":"https://api.github.com/users/alex-ppg","html_url":"https://github.com/alex-ppg","followers_url":"https://api.github.com/users/alex-ppg/followers","following_url":"https://api.github.com/users/alex-ppg/following{/other_user}","gists_url":"https://api.github.com/users/alex-ppg/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-ppg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-ppg/subscriptions","organizations_url":"https://api.github.com/users/alex-ppg/orgs","repos_url":"https://api.github.com/users/alex-ppg/repos","events_url":"https://api.github.com/users/alex-ppg/events{/privacy}","received_events_url":"https://api.github.com/users/alex-ppg/received_events","type":"User","site_admin":false},"created_at":"2018-05-16T12:06:32Z","updated_at":"2018-05-16T12:06:32Z","author_association":"NONE","body":"@chriseth \r\n> We should clarify that in the documentation. Your desired behaviour would result in far too big complexity in the compiler and thus would be dangerous to implement at this stage of evolution of the language.\r\n\r\nMy desired behaviour can be observed in the following pseudo-code:\r\n\r\n```js\r\nif (contractVersion < compilerVersion) {\r\n    showWarning(\"You are using a higher compiler version than the one specified by the 'pragma' keyword, your code may not compile at an earlier version. Consider using 'pragma solidity ^\" + compilerVersion + \";' to avoid compatibility issues.\");\r\n} else if (contractVersion == compilerVersion) {\r\n    // ...\r\n} else {\r\n    // ...\r\n}\r\n```\r\n\r\nIf the `pragma solidity` keyword does not exist within the contract, your compiler already suggests using the current compiler version as the one for it. Additionally, the warning is worded as such:\r\n\r\n> Warning: Source file does not specify required compiler version!\r\n\r\nFurther contributing to the fact that the `pragma solidity` keyword with the `^` character denotes \"*This smart contract requires you to use a compiler versioned at or above the one specified by the `pragma`*\" which is false, as your contract requires you to use a higher compiler version based on the keywords used within.\r\n\r\nI am not suggesting scanning the contract itself for features that do not exist in the `pragma` specified, **I am suggesting simply comparing the compiler version and contract version and if the compiler is at a higher version, show a warning**. I do not really see the dangerous complexity in that.\r\n    "}}
{"actor":{"display_login":"alex-ppg"}}