]> gitweb.factorcode.org Git - factor.git/commitdiff
throw a friendlier error when attempting to create a struct without slots
authorJoe Groff <arcata@gmail.com>
Thu, 27 Aug 2009 03:37:59 +0000 (22:37 -0500)
committerJoe Groff <arcata@gmail.com>
Thu, 27 Aug 2009 03:37:59 +0000 (22:37 -0500)
basis/classes/struct/struct-tests.factor
basis/classes/struct/struct.factor

index f19d71974fe598dbb5c464472208cea275ba5e57..64b8ba83e259246bbb4749e4a09f569ecbf5da5e 100644 (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 }
index 93cb8e3203342f483ff051dfb6745acffc60add2..52f3b7df9f4d7b8e33643769c38e32fd9dea2a68 100644 (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