News for hackers. Stuff that matters.
Re:State of Valhalla by hashmash on Friday December 24, 2021 @12:05AM (#29670449)
Re:State of Valhalla by overgard on Friday December 24, 2021 @08:34AM (#29673428)
That's definitely interesting, but I feel like C#'s approach of just creating a new set of containers for generics aged way better. It feels silly that I'm paying a tax in 2021 on a decision made in 2004 to be backwards compatible to code written in like 1996
Re:State of Valhalla by Joker_vD on Friday December 24, 2021 @08:26AM (#29673372)
> The language actually provides quite a strong safety guarantee for generics, as long as we follow the rules:

    If a program compiles with no unchecked or raw warnings, the synthetic casts inserted by the compiler will never fail.
Huh. That was written in 2020, four years after it was shown how to write a very small program that "compiles with no unchecked or raw warnings", and yet "the synthetic casts inserted by the compiler" will fail at run time [0]:

    class Unsound {
        static class Constrain<A, B extends A> {}

        static class Bind<A> {
            <B extends A>
            A upcast(Constrain<A, B> constrain, B b) {
                return b;
            }
        }

        static <T, U> U coerce(T t) {
            Constrain<U, ? super T> constrain = null;
            Bind<U> bind = new Bind<U>();
            return bind.upcast(constrain, t);
        }

        public static void main(String[] args) {
            String zero = Unsound.<Integer, String>coerce(0);
        }
    }
[0] N. Amin, R. Tate "Java and Scala's type systems are unsound: the existential crisis of null pointers", https://dl.acm.org/doi/pdf/10.1145/2983990.2984004
Re:State of Valhalla by hashmash on Friday December 24, 2021 @11:19AM (#29674807)
The sample program doesn't compile: Unsound.java:16: error: method upcast in class Bind<A> cannot be applied to given types; return bind.upcast(constrain, t);