After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 769501 - Return type mismatch error message is unhelpful
Return type mismatch error message is unhelpful
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Errors
0.32.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-08-04 07:33 UTC by Timm Bäder
Modified: 2016-11-05 20:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
valamethod: Print both expected and encountered type on mismatch (1.03 KB, patch)
2016-08-04 07:33 UTC, Timm Bäder
none Details | Review
example of the error message from a class implementing an interface (255 bytes, text/plain)
2016-09-11 14:51 UTC, Al Thomas
  Details
example of the error message from a class as a subtype, with the class's supertype also being a subtype (373 bytes, text/plain)
2016-09-11 14:54 UTC, Al Thomas
  Details
method: Print encountered type if return types mismatch (1.10 KB, patch)
2016-11-05 13:04 UTC, Timm Bäder
committed Details | Review

Description Timm Bäder 2016-08-04 07:33:22 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.
Comment 1 Al Thomas 2016-08-31 18:19:51 UTC
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'"
Comment 2 Timm Bäder 2016-08-31 18:44:10 UTC
Try implementing an interface.
Comment 3 Al Thomas 2016-09-11 14:51:42 UTC
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.
Comment 4 Al Thomas 2016-09-11 14:54:46 UTC
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.
Comment 5 Al Thomas 2016-09-11 15:00:49 UTC
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.
Comment 6 Timm Bäder 2016-11-05 13:04:14 UTC
Created attachment 339171 [details] [review]
method: Print encountered type if return types mismatch
Comment 7 Al Thomas 2016-11-05 13:21:47 UTC
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
Comment 8 Rico Tzschichholz 2016-11-05 20:11:40 UTC
Attachment 339171 [details] pushed as faa7dc1 - method: Print encountered type if return types mismatch