Hacker News new | ask | show | jobs
by Ironlink 1245 days ago
I can't find anything in the linked eg-draft that would indicate that the error would "occur later". In fact, it explicitly says:

    Note too that if the canonical constructor checks invariants, then a with expression will check them too. For example:
        record Rational(int num, int denom) {
            Rational {
                if (denom == 0)
                    throw new IllegalArgumentException("denom must not be zero");
            }
        }
    If we have a rational, and say
        r with { denom = 0; }
    we will get the same exception, since what this will do is unpack the numerator and denominator into mutable locals, mutate the denominator to zero, and then feed them back to the canonical constructor -- who will throw.
1 comments

Please re-read the thread, the problem was described multiple times in it.