GithubHelp home page GithubHelp logo

Type inferrence flagged incorrectly about lint HOT 5 CLOSED

golang avatar golang commented on September 24, 2024
Type inferrence flagged incorrectly

from lint.

Comments (5)

dsymonds avatar dsymonds commented on September 24, 2024

Yes, there's a large class of things that golint gets wrong for that (the more common is when the LHS is an interface). Still, it's relatively unusual to write code like that, and you can work around it easily enough (write "var x = b(foo())"). It'll need the full typechecking wired up to do it completely correctly, and that won't happen for a while.

from lint.

peterbourgon avatar peterbourgon commented on September 24, 2024

Same root cause for this symptom?

package main

import (
    "math"
)

func main() {
    var i uint64 = math.MaxUint64
    println(i)
}
$ golint a.go
a.go:8:8: should omit type uint64 from declaration of var i; it will be inferred from the right-hand side

package main

import (
    "math"
)

func main() {
    i := math.MaxUint64
    println(i)
}
$ golint b.go
$ go run b.go
# command-line-arguments
./b.go:8: constant 18446744073709551615 overflows int

from lint.

dsymonds avatar dsymonds commented on September 24, 2024

Yes, that's the same cause.

from lint.

robert-zaremba avatar robert-zaremba commented on September 24, 2024

bumping up.

Other example

var maxTime int64 = 5 * 24 * 3600

and I want to use maxTime with other int64 values. It is ugly to write

var maxTime = int64(5 * 24 * 3600)

from lint.

mewmew avatar mewmew commented on September 24, 2024

Another example for the record:

Link to p.go: http://play.golang.org/p/9DvFBwDYlc

$ go install play/p
$ golint play/p2
play/p/p.go:8:12: should omit type T from declaration of var mask; it will be inferred from the right-hand side

Link to update version of p.go: http://play.golang.org/p/sGuwidVxjN

$ go install play/p
# play/p
play/p/p.go:9: invalid operation: t & mask (mismatched types T and int)

from lint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.