You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/07/04 06:21:16 UTC

(groovy-website) branch asf-site updated: add 2nd image

This is an automated email from the ASF dual-hosted git repository.

paulk-asert pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git


The following commit(s) were added to refs/heads/asf-site by this push:
     new aa1af9b  add 2nd image
aa1af9b is described below

commit aa1af9b81551e06d2360e9c7f41968fb1fcb077c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jul 4 16:21:06 2026 +1000

    add 2nd image
---
 site/src/site/blog/groovy6-formal-methods.adoc |  30 +++++++++++++++++++------
 site/src/site/blog/img/fizzbuzz_junit.png      | Bin 0 -> 561076 bytes
 site/src/site/blog/img/fizzbuzz_verified.png   | Bin 553545 -> 509982 bytes
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/site/src/site/blog/groovy6-formal-methods.adoc b/site/src/site/blog/groovy6-formal-methods.adoc
index 2d68d53..e44459f 100644
--- a/site/src/site/blog/groovy6-formal-methods.adoc
+++ b/site/src/site/blog/groovy6-formal-methods.adoc
@@ -19,9 +19,15 @@ methods* — has long felt like a separate world: a different language
 you drive by hand (Isabelle, Lean).
 
 This post is about how much of that world is reachable from ordinary
-Groovy 6 — and it is more than you might expect as this image shows:
+Groovy 6 — and it is more than you might expect. As a taste: that is
+runtime metaclass programming below, *verified against an exact
+specification at compile time* — and when the spec is wrong, the compiler
+answers with the input that breaks it:
 
-image:img/fizzbuzz_verified.png[can you verify dynamic groovy?]
+image:img/fizzbuzz_verified.png["metaclass FizzBuzz — verified, and refuted with a counterexample, at compile time",width=800]
+
+(How a metaclass method can be type-checked at all, let alone proved, is a
+story for <<dynamic-groovy,later in the post>>.)
 
 Two things matter, and
 it is worth being precise about which is which:
@@ -737,6 +743,7 @@ accepts a larger overdraft verifies as substitutable; a `RestrictedAccount`
 that demands a minimum balance is refuted, with the input that breaks
 substitutability.
 
+[[dynamic-groovy]]
 *Even (some) dynamic Groovy.* Everything above lives in Groovy's statically
 checkable subset — `@TypeChecked` is the front door, so runtime
 metaprogramming has been out of scope by construction. But Groovy's type
@@ -753,13 +760,16 @@ Groovy and emojis] verify against exact specifications this way:
 
 [source,groovy]
 ----
-static {
-    Integer.metaClass.multiply = { String s -> delegate == 0 ? s : '' }
-}
-@Ensures({ result == (n % 3 == 0 && n % 5 == 0 ? '🥤🐝' : n % 3 == 0 ? '🥤' : n % 5 == 0 ? '🐝' : '') })
+Integer.metaClass.multiply = { String s -> delegate == 0 ? s : '' }
+
+@Ensures({ result == (n % 15 == 0 ? '🥤🐝' : n % 3 == 0 ? '🥤' : n % 5 == 0 ? '🐝' : '') })
 static String fizzbuzz(int n) { (n % 3) * '🥤' + (n % 5) * '🐝' }               // VERIFIED
 ----
 
+(That's a script: the registration is a plain top-level statement — only the
+method is `@TypeChecked`, and the pack finds the registration in the script
+body.)
+
 The gate is deliberately narrow and evidence-backed: no visible registration,
 no blessing — the code stays a compile error, exactly as `@TypeChecked`
 demands.
@@ -846,7 +856,13 @@ repro (JUnit):
 +
 The test is green _while the bug is live_ (the call really throws), so it
 confirms the compile-time counterexample is a genuine runtime failure; fix
-the code and flip it into a regression.
+the code and flip it into a regression. On the metaclass FizzBuzz from the
+introduction, the same knob pairs the generated test with the other half of
+the graceful-degradation story — run _without_ the verifier,
+`groovy-contracts` enforces the same broken spec and power-asserts the
+violation at the solver's counterexample:
++
+image:img/fizzbuzz_junit.png["the counterexample as a runnable JUnit test, plus the runtime power assert",width=800]
 * `VERIFY_SUGGEST=contract` abduces the missing precondition — for the
 unguarded `g`, it suggests `+@Requires({ 0 <= i && i < a.size() })+`, in your
 own spelling, ready to paste.
diff --git a/site/src/site/blog/img/fizzbuzz_junit.png b/site/src/site/blog/img/fizzbuzz_junit.png
new file mode 100644
index 0000000..38d1396
Binary files /dev/null and b/site/src/site/blog/img/fizzbuzz_junit.png differ
diff --git a/site/src/site/blog/img/fizzbuzz_verified.png b/site/src/site/blog/img/fizzbuzz_verified.png
index 80fcd5e..8f2751f 100644
Binary files a/site/src/site/blog/img/fizzbuzz_verified.png and b/site/src/site/blog/img/fizzbuzz_verified.png differ