golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.91k stars 17.65k forks source link

x/text/language: Matcher returns Arabic with No confidence instead of falling back to first language #63330

Open iandees opened 1 year ago

iandees commented 1 year ago

What version of Go are you using (go version)?

$ go version
go version go1.21.0 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/idees/Library/Caches/go-build'
GOENV='/Users/idees/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/idees/redacted/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/idees/redacted/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.0/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.0/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='redacted'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/l1/mykxjxqx4sggl2dq3144wcym0000gn/T/go-build2246364886=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I have a language.Matcher built with an array of languages. According to the doc for NewMatcher, "The first element is used as the default value in case no match is found" so I expected language.English to be returned for a language that was not added to the matcher. For example, when I pass in the parsed pa-PK, I get language.Arabic with a confidence enum of No.

https://go.dev/play/p/qjnoDk9kXXM

What did you expect to see?

I expected a match to language.English, the default language in the matcher.

What did you see instead?

I get language.Arabic with a confidence enum of No.

prattmic commented 1 year ago

cc @mpvl