GNOME Bugzilla – Bug 769501
Return type mismatch error message is unhelpful
Last modified: 2016-11-05 20:11:44 UTC
Created attachment 332697 [details] [review] valamethod: Print both expected and encountered type on mismatch Would be much more helpful if valac actually said what the expected return type is and what it encountered when parsing. Patch attached.
Can you supply an example of when this message is shown. I've tried: void main () { test(); } Test test () { var a = new Mismatch(); return a; } class Test { } class Mismatch { } but this produces "Return: Cannot convert from `Mismatch' to `Test'"
Try implementing an interface.
Created attachment 335309 [details] example of the error message from a class implementing an interface Error message is: class_with_interface.vala:7.2-7.21: error: overriding method `Example.test' is incompatible with base method `TestOfReturnType.test': incompatible return type. Expected Test but got Mismatch.
Created attachment 335310 [details] example of the error message from a class as a subtype, with the class's supertype also being a subtype Error message is: class_subtype.vala:7.2-7.30: error: overriding method `Example.test' is incompatible with base method `TestParent.test': incompatible return type. Expected Test but got Mismatch. The base method shows the correct base type.
Review of attachment 332697 [details] [review]: Patch appears to work in all the right places. All I would suggest is making the message one sentence instead of two. So "incompatible return type. Expected Test but got Mismatch." would be something like "expected return type of `Test' but got `Mismatch'" This makes the full message more readable: "error: overriding method `Example.test' is incompatible with base method `TestOfReturnType.test': expected return type of `Test' but got `Mismatch'" Also note it appears to be the convention that identifiers are in `' quotes. Although personally I prefer '' quotes.
Created attachment 339171 [details] [review] method: Print encountered type if return types mismatch
Review of attachment 339171 [details] [review]: Patch applies and vala compiles fine. Messages produces are good. From the examples above the new messages are: class_with_interface.vala:7.2-7.21: error: overriding method `Example.test' is incompatible with base method `TestOfReturnType.test': Base method expected return type `Test', but `Mismatch' was provided. class_subtype.vala:7.2-7.30: error: overriding method `Example.test' is incompatible with base method `TestParent.test': Base method expected return type `Test', but `Mismatch' was provided. I'm not sure about the full stop at the end because this doesn't appear in other error messages, but that's a trivial point. Thanks for the patch
Attachment 339171 [details] pushed as faa7dc1 - method: Print encountered type if return types mismatch