mattn / go-runewidth

wcwidth for golang
MIT License
610 stars 94 forks source link

Update DefaultCondition in init() function. #23

Closed markus-oberhumer closed 6 years ago

markus-oberhumer commented 6 years ago

This is an oversight in git commit ef4e261f1f0f2198dbea63dfc6639910969ef297.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.008%) to 98.758% when pulling faea1446f9c38537125a59acca15b5784e13b300 on markus-oberhumer:fix-DefaultCondition into ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb on mattn:master.

mattn commented 6 years ago

This break compatibility

markus-oberhumer commented 6 years ago

Git commit ef4e261f1f0f2198dbea63dfc6639910969ef297 broke the initialization of DefaultCondition.

So was this done on purpose?

mattn commented 6 years ago

What do you mean broke?

mattn commented 6 years ago

FYI, Your commit change the type of DefaultCondition.

markus-oberhumer commented 6 years ago

Well, after git commit ef4e261f1f0f2198dbea63dfc6639910969ef297 the value of DefaultCondition.EastAsianWidth is always false.

package main

import "fmt"

type Condition struct {
        EastAsianWidth bool
}

var (
        // EastAsianWidth will be set true if the current locale is CJK
        EastAsianWidth bool

        // DefaultCondition is a condition in current locale
        DefaultCondition = &Condition{EastAsianWidth}
)

func init() {
        EastAsianWidth = true // ASSUME true
}

func main() {
        fmt.Printf("%v %v\n", EastAsianWidth, DefaultCondition.EastAsianWidth)
}
markus-oberhumer commented 6 years ago

FYI, Your commit change the type of DefaultCondition.

Yes, just noticed that as well. But why is DefaultCondition a pointer in the first place?

markus-oberhumer commented 6 years ago

Ok, I've updated the pull request so that the type of DefaultCondition is unchanged.

Please feel free to close this request if you think the current version is correct. Thanks!

mattn commented 6 years ago

Thank you. I noticed what you mean and this is my bug just now.