aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-02-05 22:46:30 +0000
committergingerBill <bill@gingerbill.org>2018-02-05 22:46:30 +0000
commit92780e2683927b75d2b4a35e96cf4ebe0637006c (patch)
tree34c74f47b549d71496206d63324ee1a90981d10a /examples
parent2891988d3bd04c173f79eb462d2f8dfd58d9c171 (diff)
`distinct` keyword for type declarations
Diffstat (limited to 'examples')
-rw-r--r--examples/demo.odin22
1 files changed, 18 insertions, 4 deletions
diff --git a/examples/demo.odin b/examples/demo.odin
index 3152ac5c5..ab45dae85 100644
--- a/examples/demo.odin
+++ b/examples/demo.odin
@@ -22,7 +22,7 @@ when ODIN_OS == "windows" {
@(link_name="general_stuff")
general_stuff :: proc() {
fmt.println("# general_stuff");
- { // `do` for inline statmes rather than block
+ { // `do` for inline statments rather than block
foo :: proc() do fmt.println("Foo!");
if false do foo();
for false do foo();
@@ -93,6 +93,21 @@ general_stuff :: proc() {
// Having specific sized booleans is very useful when dealing with foreign code
// and to enforce specific alignment for a boolean, especially within a struct
}
+
+ { // `distinct` types
+ // Originally, all type declarations would create a distinct type unless #type_alias was present.
+ // Now the behaviour has been reversed. All type declarations create a type alias unless `distinct` is present.
+ // If the type expression is `struct`, `union`, `enum`, `proc`, or `bit_field`, the types will always been distinct.
+
+ Int32 :: i32;
+ compile_assert(Int32 == i32);
+
+ My_Int32 :: distinct i32;
+ compile_assert(My_Int32 != i32);
+
+ My_Struct :: struct{x: int};
+ compile_assert(My_Struct != struct{x: int});
+ }
}
default_struct_values :: proc() {
@@ -601,7 +616,7 @@ array_programming :: proc() {
}
{
- Vector3 :: [3]f32;
+ Vector3 :: distinct [3]f32;
a := Vector3{1, 2, 3};
b := Vector3{5, 6, 7};
c := (a * b)/2 + 1;
@@ -675,7 +690,7 @@ enum_export :: proc() {
}
main :: proc() {
- when true {
+ when false {
general_stuff();
default_struct_values();
union_type();
@@ -687,4 +702,3 @@ main :: proc() {
enum_export();
}
}
-