Skip to content

Types only some languages have

A record with a short, a char or a byte[] in it is ordinary Java, and until recently any(…) refused it. Code that keeps an unsigned 64-bit counter in a long, as many wire formats send it, has a bug at 2^63 that no long ever shows, because 2^64−1 reads as −1. Each language has types the others don’t, and a test that only draws what all of them share misses those bugs.

proptastic names each type once and draws it where your language has it. Where it doesn’t, the contract every edition is checked against says so, with what to use instead, so no edition makes up a type its language lacks. This page shows what each edition draws, and how to test the Java cases that need a second thought.

TypeJavaRustSwiftSimplest
signed 8-bit integersbytei8Int80
signed 16-bit integersshorti16Int160
signed 32-bit integersinti32Int320
signed 64-bit integerslongi64Int640
signed 128-bit integersnone (J9)i128Int128 (macOS 15, iOS 18)0
unsigned 8-bit integersnone (J9)u8UInt80
unsigned 16-bit integersnone (J9)u16UInt160
unsigned 32-bit integersnone (J9)u32UInt320
unsigned 64-bit integersnone (J9)u64UInt640
unsigned 128-bit integersnone (J9)u128UInt128 (macOS 15, iOS 18)0
signed integers of the platform's width, drawn through 64 bitsnone (J9)isizeInt0
unsigned integers of the platform's width, drawn through 64 bitsnone (J9)usizeUInt0
32-bit floating pointfloatf32Float0.0
64-bit floating pointdoublef64Double0.0
one character, as strings draw it (E26)charcharCharactera
arbitrary-precision integersjava.math.BigIntegernum_bigint::BigIntnone (S4)0
exact decimalsjava.math.BigDecimalrust_decimal::DecimalDecimal0

What an edition lacks, and what to use instead

IdLacksUse instead
J9unsigned, 128-bit and platform-width integersbigIntegers().atLeast(BigInteger.ZERO).atMost(…) for an unsigned or a 128-bit value; longs() only for a 64-bit pattern the code already reads as unsigned, such as with Long.toUnsignedString.
S4arbitrary-precision integersintegers(Int128.self), the range an unbounded bigIntegers() draws elsewhere.

Java has no unsigned 64-bit type, so code keeps one in a long and treats it as unsigned. Draw it as what it means, a number from 0 to 2^64−1, with bigIntegers(), not as a long: a long would shrink toward the wrong zero and never reach the values past 2^63 as large numbers.

TypesTest.java
static final BigInteger TWO_TO_64 = BigInteger.ONE.shiftLeft(64);
/** Every unsigned 64-bit value, drawn as itself, not as signed bits. */
static Domain<BigInteger> unsigned64() {
return bigIntegers().atLeast(BigInteger.ZERO).lessThan(TWO_TO_64);
}

Here’s a comparison that forgets the values are unsigned:

Counters.java
/** Whether counter {@code a} is past {@code b}, both unsigned. */
static boolean isPast(long a, long b) {
return a > b;
}
TypesTest.java
@Test
void aLargerCounterIsPast() {
forAll(unsigned64(), unsigned64())
.check(
(later, earlier) -> {
long laterBits = later.longValue();
long earlierBits = earlier.longValue();
boolean past = Counters.isPast(laterBits, earlierBits);
assertEquals(later.compareTo(earlier) > 0, past);
});
}
Terminal window
expected: <false> but was: <true>
aLargerCounterIsPast failed after 1 try (seed 0x5eed)
shrunk counterexample:
later = 0, earlier = 9223372036854775808
pin it:
.example(
/* later */ new BigInteger("0"),
/* earlier */ new BigInteger("9223372036854775808"))
rerun:
PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'TypesTest.aLargerCounterIsPast'

The counterexample is a number past 2^63, printed as itself. Long.compareUnsigned(a, b) > 0 is the fix. A value past 64 bits is still drawn from ordinary choices, several of them, so it saves, replays and shrinks like any other.

any(…) draws every primitive, so a record with a byte or a short component needs nothing more. On its own, a byte is a bounded integer, and the same values, edges and shrinks come from one line:

TypesTest.java
static Domain<Byte> flags() {
var range = integers().atLeast(Byte.MIN_VALUE).atMost(Byte.MAX_VALUE);
return range.map(number -> (byte) (int) number);
}

Java has no result type. A sealed interface of two records is one, and oneOf draws it, the success first, so a counterexample shrinks to a success where it can:

TypesTest.java
sealed interface Parsed permits Parsed.Ok, Parsed.Err {
record Ok(int value) implements Parsed {}
record Err(String message) implements Parsed {}
}
static Domain<Parsed> results() {
return oneOf(integers().map(Parsed.Ok::new), strings().map(Parsed.Err::new));
}

Rust’s Result and Swift’s Result are drawn by type, the same way round.

  • Rust draws every integer width, i8 to i128 and u8 to u128, with integers::<u64>(), and owned values only: String, never &str.
  • Swift draws Int128 and UInt128 on macOS 15 and iOS 18 or later, and Float16 where it compiles. Its .ofLength(5) counts Unicode scalars, as every edition counts code points, so a string with a combining accent can have a count of 4: #expect(s.count == 5) would be a property about Unicode, not about your code.
  • Half floats are on nightly Rust and in a Java incubator only: build them from the 16-bit integer that holds their bits, with a crate such as Rust’s half.

Formats covers base64, hex and the formats that stay recipes.

Privacy