|
1 | 1 | #![allow(non_upper_case_globals)] |
2 | 2 | use crate::cruby::{Qfalse, Qnil, Qtrue, VALUE, RUBY_T_ARRAY, RUBY_T_STRING, RUBY_T_HASH}; |
3 | | -use crate::cruby::{rb_cInteger, rb_cFloat, rb_cArray, rb_cHash, rb_cString, rb_cSymbol, rb_cObject, rb_cTrueClass, rb_cFalseClass, rb_cNilClass, rb_cRange}; |
| 3 | +use crate::cruby::{rb_cInteger, rb_cFloat, rb_cArray, rb_cHash, rb_cString, rb_cSymbol, rb_cObject, rb_cTrueClass, rb_cFalseClass, rb_cNilClass, rb_cRange, rb_cSet}; |
4 | 4 | use crate::cruby::ClassRelationship; |
5 | 5 | use crate::cruby::get_class_name; |
6 | 6 | use crate::cruby::rb_mRubyVMFrozenCore; |
@@ -195,6 +195,9 @@ impl Type { |
195 | 195 | else if is_string_exact(val) { |
196 | 196 | Type { bits: bits::StringExact, spec: Specialization::Object(val) } |
197 | 197 | } |
| 198 | + else if val.class_of() == unsafe { rb_cSet } { |
| 199 | + Type { bits: bits::SetExact, spec: Specialization::Object(val) } |
| 200 | + } |
198 | 201 | else if val.class_of() == unsafe { rb_cObject } { |
199 | 202 | Type { bits: bits::ObjectExact, spec: Specialization::Object(val) } |
200 | 203 | } |
@@ -394,6 +397,7 @@ impl Type { |
394 | 397 | if self.is_subtype(types::NilClassExact) { return Some(unsafe { rb_cNilClass }); } |
395 | 398 | if self.is_subtype(types::ObjectExact) { return Some(unsafe { rb_cObject }); } |
396 | 399 | if self.is_subtype(types::RangeExact) { return Some(unsafe { rb_cRange }); } |
| 400 | + if self.is_subtype(types::SetExact) { return Some(unsafe { rb_cSet }); } |
397 | 401 | if self.is_subtype(types::StringExact) { return Some(unsafe { rb_cString }); } |
398 | 402 | if self.is_subtype(types::SymbolExact) { return Some(unsafe { rb_cSymbol }); } |
399 | 403 | if self.is_subtype(types::TrueClassExact) { return Some(unsafe { rb_cTrueClass }); } |
@@ -585,6 +589,21 @@ mod tests { |
585 | 589 | assert_eq!(types::Integer.inexact_ruby_class(), None); |
586 | 590 | } |
587 | 591 |
|
| 592 | + #[test] |
| 593 | + fn set() { |
| 594 | + assert_subtype(types::SetExact, types::Set); |
| 595 | + assert_subtype(types::SetSubclass, types::Set); |
| 596 | + } |
| 597 | + |
| 598 | + #[test] |
| 599 | + fn set_has_ruby_class() { |
| 600 | + crate::cruby::with_rubyvm(|| { |
| 601 | + assert_eq!(types::SetExact.runtime_exact_ruby_class(), Some(unsafe { rb_cSet })); |
| 602 | + assert_eq!(types::Set.runtime_exact_ruby_class(), None); |
| 603 | + assert_eq!(types::SetSubclass.runtime_exact_ruby_class(), None); |
| 604 | + }); |
| 605 | + } |
| 606 | + |
588 | 607 | #[test] |
589 | 608 | fn display_exact_bits_match() { |
590 | 609 | assert_eq!(format!("{}", Type::fixnum(4)), "Fixnum[4]"); |
|
0 commit comments