On Fri, Feb 11, 2022 at 12:51 PM Kamil Ziemian <kziemian...@gmail.com>
wrote:

> I'm now trying to play with compilers with this construction.
> > type someDifferentInt[float64] int
> In Go 1.17 I get this complain
> > invalid array bound float64
> > type float64 is not an expression
> while in Go 1.18beta2 I get
> > float64 (type) is not an expression
> It probably need be this way, that with using "[T Constraint]" to define
> (?) type parameters, compiler can't says that it is "invalid array bound
> float64", but new error message is still less useful. I guess we need to
> live with that.
>

I can't see why the parser can't see that this should (if anything) be
interpreted as an array type declaration. To me, this seems like a
regression. I'd suggest maybe filing an issue.


> > type someOtherInt[float64 float64] int
> This is awful thing to write, but I still perplexed by what compilers say.
> Go 1.17:
> > syntax error: unexpected float64, expecting ]
> Go 1.18beta2:
> > cannot use a type parameter as constraint
>

This error message seems reasonably clear to me. You are declaring a type
parameter `float64` with constraint `float64`. It tells you that you can't
use type parameters as constraints.


>
> This example is to compare Go compilers with and without generics.
> > type someAnotherInt[T any] int
> Go 1.17:
> > syntax error: unexpected any, expecting ]
>
> Go 1.18beta2: it compile just fine. Can someone explain me, why compiler
> can't throw an error when it find unused type parameter? I like that in Go
> unused variable, or import, is compile time error and I would appreciate
> the same behavior with unused type parameters.
>
> I need to go for a while, I will go back with more questions about what
> you can get when using "[]" in Go.
>
> Best,
> Kamil
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/b085b991-e59e-4225-a4d6-36b2391e1dc2n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/b085b991-e59e-4225-a4d6-36b2391e1dc2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfFET%3DRVRq6%2BtAtG4Xi0%2BhUMOxxwi1qAH8GHFdzc%3DzTLyw%40mail.gmail.com.

Reply via email to