From a7637c6b3093e751734d5a94333e85363001d7ea Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Wed, 4 Nov 2026 17:33:00 +0000 Subject: [PATCH] Meaningful error message for InstallMethodWithRandomSource for a constructor --- lib/random.gi | 7 ++++++- tst/testinstall/method.tst | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/random.gi b/lib/random.gi index bea6cfb0b6..2177f1c171 100644 --- a/lib/random.gi +++ b/lib/random.gi @@ -255,6 +255,11 @@ end ); return function(args...) local filterpos, i, func, info; + if Length(args) < 2 then + ErrorNoReturn("Expected at least 2 arguments, found ", Length(args)); + elif IS_CONSTRUCTOR(args[1]) then + ErrorNoReturn("First argument must not be a constructor"); + fi; # Check we understand arguments # Second value must be an info string if not IsString(args[2]) then @@ -263,7 +268,7 @@ end ); # Info strings always tend to begin 'for ', and here we want # to be able to edit it, so we check. - if args[2]{[1..23]} <> "for a random source and" then + if Length(args[2]) < 23 or args[2]{[1..23]} <> "for a random source and" then ErrorNoReturn("Info string must begin 'for a random source and'"); fi; diff --git a/tst/testinstall/method.tst b/tst/testinstall/method.tst index 074784b79f..7c2e98e54f 100644 --- a/tst/testinstall/method.tst +++ b/tst/testinstall/method.tst @@ -33,4 +33,10 @@ gap> List(Concatenation(funcs, ranks), NameFunction); [ "cheese method", "cheese for a list", "func3", "Priority calculation for cheese", "Priority calculation for cheese for a list", "rank3" ] + +# Check errors from InstallMethodWithRandomSource for a constructor +gap> DeclareConstructor("TestCons", [IsRandomSource, IsObject]); +gap> InstallMethodWithRandomSource(TestCons, "for a random source and", +> [IsRandomSource, IsObject], ReturnFail); +Error, First argument must not be a constructor gap> STOP_TEST("method.tst");