Skip to content

Commit 6938818

Browse files
committed
out of order variable corrections
1 parent 821aac7 commit 6938818

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

internal/repl/repl.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,13 @@ func (s *Session) separateEvalStmt(in string) error {
447447
if strings.LastIndex(line, "}") == len(line)-1 {
448448
bracketCount--
449449
}
450+
if strings.LastIndex(line, "{") == len(line)-1 {
451+
bracketCount++
452+
}
450453
stmtLines = append(stmtLines, line)
451454

452455
if bracketCount == 0 && len(stmtLines) > 0 {
456+
453457
if err := s.evalStmt(strings.Join(stmtLines, "\n"), true); err != nil {
454458
return err
455459
}
@@ -476,26 +480,24 @@ func (s *Session) separateEvalStmt(in string) error {
476480
// cleanEvalStmt cleans up prior print statements etc.
477481
func (s *Session) cleanEvalStmt(in string) error {
478482
var stmtLines []string
479-
var exprCount int
480483

481484
inLines := strings.Split(in, "\n")
482485

483486
for _, line := range inLines {
484487

485-
if _, err := s.evalExpr(line); err != nil {
486-
stmtLines = append(stmtLines, line)
488+
beforeLines := len(s.mainBody.List)
489+
if expr, err := s.evalExpr(line); err == nil {
490+
if !s.isPureExpr(expr) {
491+
s.mainBody.List = s.mainBody.List[0:beforeLines]
492+
stmtLines = append(stmtLines, line)
493+
}
487494
continue
488495
}
489-
490-
exprCount++
496+
stmtLines = append(stmtLines, line)
491497
}
492498

493499
if len(stmtLines) != 0 {
494-
var noPrint bool
495-
if exprCount > 0 {
496-
noPrint = true
497-
}
498-
if err := s.evalStmt(strings.Join(stmtLines, "\n"), noPrint); err != nil {
500+
if err := s.evalStmt(strings.Join(stmtLines, "\n"), true); err != nil {
499501
return err
500502
}
501503
}

0 commit comments

Comments
 (0)