@@ -729,3 +729,153 @@ for line <- os.Stdin {
729
729
002: 5: 2 | println | builtin println
730
730
003: 5:10 | line | var line string` )
731
731
}
732
+
733
+ func TestLambdaExpr (t * testing.T ) {
734
+ testGopInfo (t , `package main
735
+ func Map(c []float64, t func(float64) float64) {
736
+ // ...
737
+ }
738
+
739
+ func Map2(c []float64, t func(float64) (float64, float64)) {
740
+ // ...
741
+ }
742
+
743
+ Map([1.2, 3.5, 6], x => x * x)
744
+ Map2([1.2, 3.5, 6], x => (x * x, x + x))
745
+ ` , `` , `== types ==
746
+ 000: 2:12 | []float64 *ast.ArrayType | type : []float64 | type
747
+ 001: 2:14 | float64 *ast.Ident | type : float64 | type
748
+ 002: 2:25 | func(float64) float64 *ast.FuncType | type : func(float64) float64 | type
749
+ 003: 2:30 | float64 *ast.Ident | type : float64 | type
750
+ 004: 2:39 | float64 *ast.Ident | type : float64 | type
751
+ 005: 6:13 | []float64 *ast.ArrayType | type : []float64 | type
752
+ 006: 6:15 | float64 *ast.Ident | type : float64 | type
753
+ 007: 6:26 | func(float64) (float64, float64) *ast.FuncType | type : func(float64) (float64, float64) | type
754
+ 008: 6:31 | float64 *ast.Ident | type : float64 | type
755
+ 009: 6:41 | float64 *ast.Ident | type : float64 | type
756
+ 010: 6:50 | float64 *ast.Ident | type : float64 | type
757
+ 011: 10: 1 | Map *ast.Ident | value : func(c []float64, t func(float64) float64) | value
758
+ 012: 10: 1 | Map([1.2, 3.5, 6], x => x * x) *ast.CallExpr | void : () | no value
759
+ 013: 10: 6 | 1.2 *ast.BasicLit | value : untyped float = 1.2 | constant
760
+ 014: 10:11 | 3.5 *ast.BasicLit | value : untyped float = 3.5 | constant
761
+ 015: 10:16 | 6 *ast.BasicLit | value : untyped int = 6 | constant
762
+ 016: 10:25 | x *ast.Ident | var : float64 | variable
763
+ 017: 10:25 | x * x *ast.BinaryExpr | value : float64 | value
764
+ 018: 10:29 | x *ast.Ident | var : float64 | variable
765
+ 019: 11: 1 | Map2 *ast.Ident | value : func(c []float64, t func(float64) (float64, float64)) | value
766
+ 020: 11: 1 | Map2([1.2, 3.5, 6], x => (x * x, x + x)) *ast.CallExpr | void : () | no value
767
+ 021: 11: 7 | 1.2 *ast.BasicLit | value : untyped float = 1.2 | constant
768
+ 022: 11:12 | 3.5 *ast.BasicLit | value : untyped float = 3.5 | constant
769
+ 023: 11:17 | 6 *ast.BasicLit | value : untyped int = 6 | constant
770
+ 024: 11:27 | x *ast.Ident | var : float64 | variable
771
+ 025: 11:27 | x * x *ast.BinaryExpr | value : float64 | value
772
+ 026: 11:31 | x *ast.Ident | var : float64 | variable
773
+ 027: 11:34 | x *ast.Ident | var : float64 | variable
774
+ 028: 11:34 | x + x *ast.BinaryExpr | value : float64 | value
775
+ 029: 11:38 | x *ast.Ident | var : float64 | variable
776
+ == defs ==
777
+ 000: 2: 6 | Map | func main.Map(c []float64, t func(float64) float64)
778
+ 001: 2:10 | c | var c []float64
779
+ 002: 2:23 | t | var t func(float64) float64
780
+ 003: 6: 6 | Map2 | func main.Map2(c []float64, t func(float64) (float64, float64))
781
+ 004: 6:11 | c | var c []float64
782
+ 005: 6:24 | t | var t func(float64) (float64, float64)
783
+ 006: 10: 1 | main | func main.main()
784
+ 007: 10:20 | x | var x float64
785
+ 008: 11:21 | x | var x float64
786
+ == uses ==
787
+ 000: 2:14 | float64 | type float64
788
+ 001: 2:30 | float64 | type float64
789
+ 002: 2:39 | float64 | type float64
790
+ 003: 6:15 | float64 | type float64
791
+ 004: 6:31 | float64 | type float64
792
+ 005: 6:41 | float64 | type float64
793
+ 006: 6:50 | float64 | type float64
794
+ 007: 10: 1 | Map | func main.Map(c []float64, t func(float64) float64)
795
+ 008: 10:25 | x | var x float64
796
+ 009: 10:29 | x | var x float64
797
+ 010: 11: 1 | Map2 | func main.Map2(c []float64, t func(float64) (float64, float64))
798
+ 011: 11:27 | x | var x float64
799
+ 012: 11:31 | x | var x float64
800
+ 013: 11:34 | x | var x float64
801
+ 014: 11:38 | x | var x float64` )
802
+ }
803
+
804
+ func TestLambdaExpr2 (t * testing.T ) {
805
+ testGopInfo (t , `package main
806
+ func Map(c []float64, t func(float64) float64) {
807
+ // ...
808
+ }
809
+
810
+ func Map2(c []float64, t func(float64) (float64, float64)) {
811
+ // ...
812
+ }
813
+
814
+ Map([1.2, 3.5, 6], x => {
815
+ return x * x
816
+ })
817
+ Map2([1.2, 3.5, 6], x => {
818
+ return x * x, x + x
819
+ })
820
+ ` , `` , `== types ==
821
+ 000: 2:12 | []float64 *ast.ArrayType | type : []float64 | type
822
+ 001: 2:14 | float64 *ast.Ident | type : float64 | type
823
+ 002: 2:25 | func(float64) float64 *ast.FuncType | type : func(float64) float64 | type
824
+ 003: 2:30 | float64 *ast.Ident | type : float64 | type
825
+ 004: 2:39 | float64 *ast.Ident | type : float64 | type
826
+ 005: 6:13 | []float64 *ast.ArrayType | type : []float64 | type
827
+ 006: 6:15 | float64 *ast.Ident | type : float64 | type
828
+ 007: 6:26 | func(float64) (float64, float64) *ast.FuncType | type : func(float64) (float64, float64) | type
829
+ 008: 6:31 | float64 *ast.Ident | type : float64 | type
830
+ 009: 6:41 | float64 *ast.Ident | type : float64 | type
831
+ 010: 6:50 | float64 *ast.Ident | type : float64 | type
832
+ 011: 10: 1 | Map *ast.Ident | value : func(c []float64, t func(float64) float64) | value
833
+ 012: 10: 1 | Map([1.2, 3.5, 6], x => {
834
+ return x * x
835
+ }) *ast.CallExpr | void : () | no value
836
+ 013: 10: 6 | 1.2 *ast.BasicLit | value : untyped float = 1.2 | constant
837
+ 014: 10:11 | 3.5 *ast.BasicLit | value : untyped float = 3.5 | constant
838
+ 015: 10:16 | 6 *ast.BasicLit | value : untyped int = 6 | constant
839
+ 016: 11: 9 | x *ast.Ident | var : float64 | variable
840
+ 017: 11: 9 | x * x *ast.BinaryExpr | value : float64 | value
841
+ 018: 11:13 | x *ast.Ident | var : float64 | variable
842
+ 019: 13: 1 | Map2 *ast.Ident | value : func(c []float64, t func(float64) (float64, float64)) | value
843
+ 020: 13: 1 | Map2([1.2, 3.5, 6], x => {
844
+ return x * x, x + x
845
+ }) *ast.CallExpr | void : () | no value
846
+ 021: 13: 7 | 1.2 *ast.BasicLit | value : untyped float = 1.2 | constant
847
+ 022: 13:12 | 3.5 *ast.BasicLit | value : untyped float = 3.5 | constant
848
+ 023: 13:17 | 6 *ast.BasicLit | value : untyped int = 6 | constant
849
+ 024: 14: 9 | x *ast.Ident | var : float64 | variable
850
+ 025: 14: 9 | x * x *ast.BinaryExpr | value : float64 | value
851
+ 026: 14:13 | x *ast.Ident | var : float64 | variable
852
+ 027: 14:16 | x *ast.Ident | var : float64 | variable
853
+ 028: 14:16 | x + x *ast.BinaryExpr | value : float64 | value
854
+ 029: 14:20 | x *ast.Ident | var : float64 | variable
855
+ == defs ==
856
+ 000: 2: 6 | Map | func main.Map(c []float64, t func(float64) float64)
857
+ 001: 2:10 | c | var c []float64
858
+ 002: 2:23 | t | var t func(float64) float64
859
+ 003: 6: 6 | Map2 | func main.Map2(c []float64, t func(float64) (float64, float64))
860
+ 004: 6:11 | c | var c []float64
861
+ 005: 6:24 | t | var t func(float64) (float64, float64)
862
+ 006: 10: 1 | main | func main.main()
863
+ 007: 10:20 | x | var x float64
864
+ 008: 13:21 | x | var x float64
865
+ == uses ==
866
+ 000: 2:14 | float64 | type float64
867
+ 001: 2:30 | float64 | type float64
868
+ 002: 2:39 | float64 | type float64
869
+ 003: 6:15 | float64 | type float64
870
+ 004: 6:31 | float64 | type float64
871
+ 005: 6:41 | float64 | type float64
872
+ 006: 6:50 | float64 | type float64
873
+ 007: 10: 1 | Map | func main.Map(c []float64, t func(float64) float64)
874
+ 008: 11: 9 | x | var x float64
875
+ 009: 11:13 | x | var x float64
876
+ 010: 13: 1 | Map2 | func main.Map2(c []float64, t func(float64) (float64, float64))
877
+ 011: 14: 9 | x | var x float64
878
+ 012: 14:13 | x | var x float64
879
+ 013: 14:16 | x | var x float64
880
+ 014: 14:20 | x | var x float64` )
881
+ }
0 commit comments