@@ -183,15 +183,19 @@ func Inline(logf func(string, ...any), caller *Caller, callee *Callee) ([]byte,
183
183
// Precise comment handling would make this a
184
184
// non-issue. Formatting wouldn't really need a
185
185
// FileSet at all.
186
- mark := out .Len ()
187
- if err := format .Node (& out , caller .Fset , res .new ); err != nil {
188
- return nil , err
189
- }
190
186
if elideBraces {
191
- // Overwrite unnecessary {...} braces with spaces.
192
- // TODO(adonovan): less hacky solution.
193
- out .Bytes ()[mark ] = ' '
194
- out .Bytes ()[out .Len ()- 1 ] = ' '
187
+ for i , stmt := range res .new .(* ast.BlockStmt ).List {
188
+ if i > 0 {
189
+ out .WriteByte ('\n' )
190
+ }
191
+ if err := format .Node (& out , caller .Fset , stmt ); err != nil {
192
+ return nil , err
193
+ }
194
+ }
195
+ } else {
196
+ if err := format .Node (& out , caller .Fset , res .new ); err != nil {
197
+ return nil , err
198
+ }
195
199
}
196
200
out .Write (caller .Content [end :])
197
201
const mode = parser .ParseComments | parser .SkipObjectResolution | parser .AllErrors
@@ -902,9 +906,6 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
902
906
// The body may use defer, arbitrary control flow, and
903
907
// multiple returns.
904
908
//
905
- // TODO(adonovan): omit the braces if the sets of
906
- // names in the two blocks are disjoint.
907
- //
908
909
// TODO(adonovan): add a strategy for a 'void tail
909
910
// call', i.e. a call statement prior to an (explicit
910
911
// or implicit) return.
@@ -942,8 +943,6 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
942
943
// - all parameters and result vars can be eliminated
943
944
// or replaced by a binding decl,
944
945
// - caller ExprStmt is in unrestricted statement context.
945
- //
946
- // If there is only a single statement, the braces are omitted.
947
946
if stmt := callStmt (caller .path , true ); stmt != nil &&
948
947
(! needBindingDecl || bindingDeclStmt != nil ) &&
949
948
! callee .HasDefer &&
@@ -956,9 +955,6 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
956
955
if needBindingDecl {
957
956
body .List = prepend (bindingDeclStmt , body .List ... )
958
957
}
959
- if len (body .List ) == 1 { // FIXME do this opt later
960
- repl = body .List [0 ] // singleton: omit braces
961
- }
962
958
res .old = stmt
963
959
res .new = repl
964
960
return res , nil
0 commit comments