throw a friendlier error when attempting to create a struct without slots

db4
Joe Groff 2009-08-26 22:37:59 -05:00
parent 53b7729f76
commit 69e640c55b
2 changed files with 13 additions and 2 deletions

View File

@ -5,7 +5,8 @@ destructors io.encodings.utf8 io.pathnames io.streams.string
kernel libc literals math multiline namespaces prettyprint
prettyprint.config see sequences specialized-arrays.ushort
system tools.test compiler.tree.debugger struct-arrays
classes.tuple.private specialized-arrays.direct.int ;
classes.tuple.private specialized-arrays.direct.int
compiler.units ;
IN: classes.struct.tests
<<
@ -22,6 +23,11 @@ IN: classes.struct.tests
"f-stdcall" libfactor-ffi-tests-path "stdcall" add-library
>>
SYMBOL: struct-test-empty
[ [ struct-test-empty { } define-struct-class ] with-compilation-unit ]
[ struct-must-have-slots? ] must-fail-with
STRUCT: struct-test-foo
{ x char }
{ y int initial: 123 }

View File

@ -12,6 +12,8 @@ IN: classes.struct
! struct class
ERROR: struct-must-have-slots ;
TUPLE: struct
{ (underlying) c-ptr read-only } ;
@ -207,7 +209,10 @@ M: struct-class heap-size
[ c-type>> c-type drop ] each ;
: (define-struct-class) ( class slots offsets-quot -- )
[ drop struct f define-tuple-class ]
[
[ struct-must-have-slots ]
[ drop struct f define-tuple-class ] if-empty
]
swap '[
make-slots dup
[ check-struct-slots ] _ [ struct-align [ align ] keep ] tri