{"action":"created","issue":{"url":"https://api.github.com/repos/colobot/colobot/issues/809","repository_url":"https://api.github.com/repos/colobot/colobot","labels_url":"https://api.github.com/repos/colobot/colobot/issues/809/labels{/name}","comments_url":"https://api.github.com/repos/colobot/colobot/issues/809/comments","events_url":"https://api.github.com/repos/colobot/colobot/issues/809/events","html_url":"https://github.com/colobot/colobot/pull/809","id":169331409,"number":809,"title":"Fixes and unit tests for inheritance","user":{"login":"melex750","id":15256309,"avatar_url":"https://avatars.githubusercontent.com/u/15256309?v=3","gravatar_id":"","url":"https://api.github.com/users/melex750","html_url":"https://github.com/melex750","followers_url":"https://api.github.com/users/melex750/followers","following_url":"https://api.github.com/users/melex750/following{/other_user}","gists_url":"https://api.github.com/users/melex750/gists{/gist_id}","starred_url":"https://api.github.com/users/melex750/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/melex750/subscriptions","organizations_url":"https://api.github.com/users/melex750/orgs","repos_url":"https://api.github.com/users/melex750/repos","events_url":"https://api.github.com/users/melex750/events{/privacy}","received_events_url":"https://api.github.com/users/melex750/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-08-04T09:31:04Z","updated_at":"2016-08-05T11:03:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/colobot/colobot/pulls/809","html_url":"https://github.com/colobot/colobot/pull/809","diff_url":"https://github.com/colobot/colobot/pull/809.diff","patch_url":"https://github.com/colobot/colobot/pull/809.patch"},"body":"The **unit tests** are somewhat big because they need\r\nto test at least three levels of inheritance.\r\n\r\n**Fixes these bugs:**\r\n\r\n**Destructors** that are expected to be called,\r\n**don't get called** after saving/reloading the game, \r\nwhen the game is saved with a running program.\r\n\r\n**RestoreState** assigns wrong IDs to subclass instance variables.\r\n\r\n**SegFault** when RestoreMethode doesn't restore a call to inherited method.\r\n Reproduce: save/reload the game while executing code inside the method.\r\n\r\n**Inheritance #540 and #683:**\r\n\r\nThis doesn't work:    ```child.grandParentMethod();```\r\n\r\nThis doesn't compile: ```Base b = new SubClass();``` <-- bug\r\nThis does compile:    ```SubClass s = new Base();``` <-- bug\r\n\r\nThis currently compiles:\r\n```c++\r\nBase b;\r\nb = new Subclass();\r\nb.overriddenMethod(); <-- calls method in base (bug)\r\n```\r\n**At runtime: won't re-assign the pointer.**\r\n```c++\r\nb = new SubClass(); <------- unless the same type is already assigned.\r\nb = new OtherSubClass(); <-- runtime: \"Wrong type for the assignment\"\r\nb = new Base();     <------- runtime: \"Wrong type for the assignment\"\r\n```\r\nImplicit downcast was already implemented and works.\r\n\r\nAll of the above also applies to **arrays of classes**.\r\n\r\n**Suggested improvement:**\r\n\r\nExplicit cast operator and remove implicit downcast.\r\n```c++\r\n  Base base = new SubClass();\r\n  SubClass s; \r\n\r\n  s = cast<SubClass>(base);\r\n  cast<SubClass>(base).x = 4.2;\r\n  cast<SubClass>(base).subclassMethod();\r\n```"},"comment":{"url":"https://api.github.com/repos/colobot/colobot/issues/comments/237823449","html_url":"https://github.com/colobot/colobot/pull/809#issuecomment-237823449","issue_url":"https://api.github.com/repos/colobot/colobot/issues/809","id":237823449,"user":{"login":"krzys-h","id":1517255,"avatar_url":"https://avatars.githubusercontent.com/u/1517255?v=3","gravatar_id":"","url":"https://api.github.com/users/krzys-h","html_url":"https://github.com/krzys-h","followers_url":"https://api.github.com/users/krzys-h/followers","following_url":"https://api.github.com/users/krzys-h/following{/other_user}","gists_url":"https://api.github.com/users/krzys-h/gists{/gist_id}","starred_url":"https://api.github.com/users/krzys-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krzys-h/subscriptions","organizations_url":"https://api.github.com/users/krzys-h/orgs","repos_url":"https://api.github.com/users/krzys-h/repos","events_url":"https://api.github.com/users/krzys-h/events{/privacy}","received_events_url":"https://api.github.com/users/krzys-h/received_events","type":"User","site_admin":false},"created_at":"2016-08-05T11:03:06Z","updated_at":"2016-08-05T11:03:06Z","body":"@CyborgMaster\r\nCBotType is just a simple enum that contains the base type like: string, int, array, pointer.\r\nCBotTypResult contains complete information about the type, like: array of ints (```int x[];```), array of strings limited to 4 values (```string x[4];```), pointer to class Y (```Y x;```), array of pointers to class Z (```Z x[];```) etc.\r\nIn some cases CBotTypResult may also store a compilation error code (from CBotError enum).\r\nSee http://compiled.colobot.info/job/colobot/job/colobot/job/dev/Doxygen/class_c_bot_1_1_c_bot_typ_result.html#details for examples.\r\n\r\nThe best way to add additional unit tests to this PR would be probably to send another PR to @melex750's repo, although I don't think I ever saw chaining PRs like that happen in practice ;)\r\n\r\nI think I'll leave figuring out the best solution to you two as I have only a very general understanding of the CBot engine and it's hard for me to even compare the changes."}}
{"actor":{"display_login":"krzys-h"}}