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

Bug 425617

Summary: Tern index parser doesn't support return type signatures
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: Michael_Rennie
Version: 5.0   
Target Milestone: 5.0 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2014-01-13 18:39:42 EST
i) When trying to hook up the postgres index to the JS content assist engine, I ran into this error about the "!ret" property (used to indicate a function's return type):

> "didn't handle special property !ret"
> parseObjType (typesFromIndexFile.js:234)
> definitionForType (typesFromIndexFile.js:312)
> parseObjType (typesFromIndexFile.js:246)
> definitionForType (typesFromIndexFile.js:312)
> parseObjType (typesFromIndexFile.js:236)
> definitionForType (typesFromIndexFile.js:312)
> parseObjType (typesFromIndexFile.js:246)
> definitionForType (typesFromIndexFile.js:312)
> addIndexInfo (typesFromIndexFile.js:375)
> addIndexData (typesFromIndexFile.js:505)
> (anonymous function) (typeEnvironment.js:59)
> (anonymous function) (typeEnvironment.js:57)


ii) I get this error from the redis index, which uses Tern's "fn(..) -> rettype" syntax:
> doctrine failure to parse: >fn(err:Error 
> ensureTypeObject (typeUtils.js:37)
> Definition (typeUtils.js:85)
> definitionForType (typesFromIndexFile.js:310)
> parseRet (typesFromIndexFile.js:167)
> ternSig2ClosureSigInternal (typesFromIndexFile.js:176)
> definitionForType (typesFromIndexFile.js:293)
> ...

The problematic syntax was this type signature (note the arrow indicating the return type). 
> "exec": "fn(callback: fn()) -> fn(err: Error, replies: Object)"
Comment 1 Michael Rennie CLA 2014-01-14 14:01:55 EST
(In reply to Mark Macdonald from comment #0)

I fixed the tests and added a couple more of them: http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=2fc052c41613cda525074712e710451852166fe5

The index parser does seem to support the 'fn()' as a parameter, for example this signature is ok:

"fn(callback: fn())"

> i) When trying to hook up the postgres index to the JS content assist
> engine, I ran into this error about the "!ret" property (used to indicate a
> function's return type):

I think this is related to the problem below.

> 
> The problematic syntax was this type signature (note the arrow indicating
> the return type). 
> > "exec": "fn(callback: fn()) -> fn(err: Error, replies: Object)"

This failure seems to be caused by the parser failing to handle the return type. For example the mentioned signature parses to "fn())->fn(err:+Error" after one pass of the index parser (BAD) and each pass whittles it down to something worse until doctrine barfs and dies trying to parse a type object from ">fn(err:+Error".
Comment 2 Michael Rennie CLA 2014-01-17 10:44:05 EST
While working on this I discovvered that the index file was wrong at that location and the output with the -> fn(err:...) was actually wrong, the function actually returns a Boolean (from inspecting the source). Looking at the parser an related Tern / Doctrine info when a function returns a function it should be written as 'Function' or '+Function', so I don;t think case is even valid.'

I'm going to close this as worksforme, I don't think we should bother trying to support expanded function return types (since we are planning to refactor all this code anyway).