Bug 356638

Summary: False-positive warning with addEventListener()
Product: [Applications] kdevelop Reporter: Francis Herne <mail>
Component: Language Support: QML/JavaScriptAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal CC: jonathan.verner
Priority: NOR    
Version First Reported In: 4.90.90   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Francis Herne 2015-12-13 23:37:29 UTC
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

addEventListener() can be called with either an object or (IME much more commonly) a function as its second argument. In the latter case, the following error or one similar to it is displayed:

Problem in Semantic analysis:
Possible type mismatch between the argument type (EventListener) and the value passed as argument (function void ())
Comment 1 Francis Herne 2015-12-13 23:57:04 UTC
This only seems to happen when the useCapture (third) argument is provided.
Comment 2 Kevin Funk 2016-03-09 07:44:13 UTC
Can you reduce that to a simple test case?
Comment 3 Francis Herne 2016-03-09 09:58:59 UTC
The 13-line example on the linked page (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#JavaScript_Content) encounters it.

Cut down further:
function someFunction() {}
var el = document.getElementById('elephant');
el.addEventListener("click", someFunction, false);
Comment 4 Francis Herne 2016-03-09 10:19:32 UTC
Whoops, missed a semicolon on the first line.

In fact, KDevelop doesn't like having an object as the second argument either (contrary to what my original report implies).

var listener = {
    handleEvent: function(event) {}
};
var el = document.getElementById('elephant');
el.addEventListener("click", listener, false);

is also flagged as an error. I think the parser is being too picky about what can be an EventListener, given JS's duck typing and lack of inheritance (before ES6).
Comment 5 Jonathan Verner 2017-06-20 16:20:33 UTC
Happens here (Kdevelop 5.1.1 AppImage) too. I can also confirm that removing the third argument of addEventListener the error is gone.
Comment 6 Kevin Funk 2017-09-15 14:55:43 UTC
Could you check if this is still valid in newer KDevelop? There's no error indicated with KDevelop 5.2 here.
Comment 7 Francis Herne 2017-09-15 15:04:36 UTC
Not reproducible for me with 5.2.