-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support explicit discriminant numbers on tag variants.
Addresses issue #1393. For now disallow disr. values unless all variants use nullary contractors (i.e. "enum-like"). Disr. values are now encoded in the crate metadata, but only when it will differ from the inferred value based on the order.
- Loading branch information
Showing
12 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//error-pattern:discriminator value already exists | ||
|
||
// black and white have the same discriminator value ... | ||
|
||
tag color { | ||
red = 0xff0000; | ||
green = 0x00ff00; | ||
blue = 0x0000ff; | ||
black = 0x000000; | ||
white = 0x000000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//error-pattern: discriminator values can only be used with enum-like tag | ||
// black and white have the same discriminator value ... | ||
|
||
tag color { | ||
red = 0xff0000; | ||
green = 0x00ff00; | ||
blue = 0x0000ff; | ||
black = 0x000000; | ||
white = 0xffffff; | ||
other (str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
tag color { | ||
red = 0xff0000; | ||
green = 0x00ff00; | ||
blue = 0x0000ff; | ||
black = 0x000000; | ||
white = 0xFFFFFF; | ||
imaginary = -1; | ||
} | ||
|
||
fn main() { | ||
test_color(red, 0xff0000, "red"); | ||
test_color(green, 0x00ff00, "green"); | ||
test_color(blue, 0x0000ff, "blue"); | ||
test_color(black, 0x000000, "black"); | ||
test_color(white, 0xFFFFFF, "white"); | ||
test_color(imaginary, -1, "imaginary"); | ||
} | ||
|
||
fn test_color(color: color, val: int, name: str) unsafe { | ||
assert unsafe::reinterpret_cast(color) == val; | ||
assert get_color_alt(color) == name; | ||
assert get_color_if(color) == name; | ||
} | ||
|
||
fn get_color_alt(color: color) -> str { | ||
alt color { | ||
red. {"red"} | ||
green. {"green"} | ||
blue. {"blue"} | ||
black. {"black"} | ||
white. {"white"} | ||
imaginary. {"imaginary"} | ||
_ {"unknown"} | ||
} | ||
} | ||
|
||
fn get_color_if(color: color) -> str { | ||
if color == red {"red"} | ||
else if color == green {"green"} | ||
else if color == blue {"blue"} | ||
else if color == black {"black"} | ||
else if color == white {"white"} | ||
else if color == imaginary {"imaginary"} | ||
else {"unknown"} | ||
} | ||
|
||
|