...

Text file src/cmd/gofmt/testdata/rewrite4.input

Documentation: cmd/gofmt/testdata

     1//gofmt -r=(x)->x
     2
     3// Copyright 2012 The Go Authors. All rights reserved.
     4// Use of this source code is governed by a BSD-style
     5// license that can be found in the LICENSE file.
     6
     7// Rewriting of parenthesized expressions (x) -> x
     8// must not drop parentheses if that would lead to
     9// wrong association of the operands.
    10// Was issue 1847.
    11
    12package main
    13
    14// From example 1 of issue 1847.
    15func _() {
    16	var t = (&T{1000}).Id()
    17}
    18
    19// From example 2 of issue 1847.
    20func _() {
    21       fmt.Println((*xpp).a)
    22}
    23
    24// Some more test cases.
    25func _() {
    26	_ = (-x).f
    27	_ = (*x).f
    28	_ = (&x).f
    29	_ = (!x).f
    30	_ = (-x.f)
    31	_ = (*x.f)
    32	_ = (&x.f)
    33	_ = (!x.f)
    34	(-x).f()
    35	(*x).f()
    36	(&x).f()
    37	(!x).f()
    38	_ = (-x.f())
    39	_ = (*x.f())
    40	_ = (&x.f())
    41	_ = (!x.f())
    42
    43	_ = ((-x)).f
    44	_ = ((*x)).f
    45	_ = ((&x)).f
    46	_ = ((!x)).f
    47	_ = ((-x.f))
    48	_ = ((*x.f))
    49	_ = ((&x.f))
    50	_ = ((!x.f))
    51	((-x)).f()
    52	((*x)).f()
    53	((&x)).f()
    54	((!x)).f()
    55	_ = ((-x.f()))
    56	_ = ((*x.f()))
    57	_ = ((&x.f()))
    58	_ = ((!x.f()))
    59
    60	_ = -(x).f
    61	_ = *(x).f
    62	_ = &(x).f
    63	_ = !(x).f
    64	_ = -x.f
    65	_ = *x.f
    66	_ = &x.f
    67	_ = !x.f
    68	_ = -(x).f()
    69	_ = *(x).f()
    70	_ = &(x).f()
    71	_ = !(x).f()
    72	_ = -x.f()
    73	_ = *x.f()
    74	_ = &x.f()
    75	_ = !x.f()
    76}

View as plain text