Skip to content

null point run smoothly and wrong result #7584

@gopherbot

Description

@gopherbot

by ZhaoChengbing87:

Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What does 'go version' print?

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. go version go1.2 linux/amd64
2. init the regexp.Regexp with a empty string
3. post the code here


package main

import (
    "fmt"
    "regexp"
)

var (
    //fileRegexp = `chat.log`
    fileRegexp string
    reg        = regexp.MustCompile(fileRegexp)
)

func main() {
    fileRegexp = `chat.log`
    var teststring = []string{"chat.log", "a", "b", "c", "not_match"}
    for _, testcase := range teststring {
        if reg.MatchString(testcase) {
            fmt.Println(testcase, "matches", fileRegexp)
        }
    }

}


What happened?
we get answers like
  chat.log matches chat.log
  a matches chat.log
  b matches chat.log
  c matches chat.log
  not_match matches chat.log
  It is obviously wrong here.
 
What should have happened instead?
  the programme should panic or report a compile error here.
Please provide any additional information below.
  No additional information needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions