Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 494572

Summary: [tern] Weird warning for custom indexed type definitions
Product: [ECD] Orion Reporter: Sebastian Pahnke <pahnke.sebastian>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, Michael_Rennie
Version: 12.0   
Target Milestone: 12.0   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
Test project none

Description Sebastian Pahnke CLA 2016-05-25 13:48:02 EDT
Consider the following tern plugin/type index:

define([
    'tern/lib/tern'
], function (tern) {

    tern.registerPlugin('test', function (server, options) {
        server.addDefs(defs);
    });

    var defs = {
        "!name": "test",
        "test": {
            "anonymizeEventInPeriod": {
                "!type": "fn(name: +Date)",
                "!doc": "Returns a new Foo object."
            },
            "foobar": {
                "!type": "fn(name: +Date)",
                "!doc": "Returns a new Foo object."
            },
        }
    };
});



If I type the following code into the editor I get a warning on anonymizeEventInPeriod saying:
'anonymizeEventInPeriod' is undefined for 'test' in test.

/* eslint-env test*/
test.anonymizeEventInPeriod(name)


What's weird about this is that I don't get a warning for the function foobar. There is also no warning if you remove name, which makes the syntax error go away. Another weird thing is that the naming and parameter type of the function anonymizeEventInPeriod has to be exactly as above (more or less: you can exchange Event with another word and still get an error; the parameter type must be an object instance).

I saw this in the code edit widget for my custom types. Maybe in the IDE you can use the tern index directly in a .tern-project file to reproduce the behavior.
Comment 1 Michael Rennie CLA 2016-05-26 15:06:50 EDT
Created attachment 262041 [details]
Test project

I can reproduce the issue using in-project definitions as well.

If you import the zipped project, I created a stand-alone index from your example plug-in. You can see it incorrectly flags the function as unknown in the 'normal' editor.
Comment 2 Michael Rennie CLA 2016-05-27 11:25:00 EDT
Fix + tests:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=52d2f95cc0b4a453dbaee21f5a3a723d410a2873

neither function is flagged now.

I ended up fixing up some weird logic in the no-undef-expression rule, and re-enabling all of the skipped tests (they all pass now).
Comment 3 Michael Rennie CLA 2016-05-27 11:27:47 EDT
*** Bug 492924 has been marked as a duplicate of this bug. ***