Declare variables in parameters of function literals
ClosedPublic

Authored by ematirov on Jun 19 2017, 12:41 PM.

Details

Summary

Consider a following code:

package main

import "fmt"

func passFuncAsArgument(a interface{}) interface{} { return a }

func main() {
    a := func(test int) (int) { return test } // Declaring a local function literal  (1)
    func(test int) (int)  { return test } (5) // Calling a anonymous function  (2)
    passFuncAsArgument(func(test int) (int) {return test }) // Passing anonymous function as argument  (3)
    fmt.Println(a(5))
}

Before this patch only in (1) case a function argument will be added as declaration.
This patch extends that to (2) and (3) cases.

This has impact on semantic highlighting for example:
Before


After

Test Plan

Tests were added and are passing fine.

Diff Detail

Repository
R59 KDevelop Go
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ematirov created this revision.Jun 19 2017, 12:41 PM
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJun 19 2017, 12:41 PM
brauch accepted this revision.Jun 19 2017, 1:10 PM

The highlighting still looks wrong but that's a different issue. Patch looks ok -- it has a test, it can't be bad ;)

This revision is now accepted and ready to land.Jun 19 2017, 1:10 PM
This revision was automatically updated to reflect the committed changes.