Could Swift detect this assertion fail at compile time?

@_fixed_layout
@usableFromInline
struct Storage 
{
    var U:Math<Float>.Mat4, // ((Float, Float, Float, Float), (...
        V:Math<Float>.Mat4, 
        W:Math<Float>.Mat4, 
        
        a:Math<Float>.V3, // (Float, Float, Float)
        _padf0:Float = 0, 
        
        b:Math<Float>.V3, 
        _padf1:Float = 0, 
        
        position:Math<Float>.V3, 
        _padf2:Float = 0
    
    init()
    {
        ...
        
        assert(MemoryLayout<Storage>.size == 240)
    }
}

wouldn’t it be nice if the compiler could run this kind of assert at compile time?

Related: Compile-Time Constant Expressions for Swift - #28 by benrimmington.

1 Like