@@ -1556,7 +1556,7 @@ impl Function {
15561556 Insn :: InvokeBlock { .. } => types:: BasicObject ,
15571557 Insn :: InvokeBuiltin { return_type, .. } => return_type. unwrap_or ( types:: BasicObject ) ,
15581558 Insn :: Defined { pushval, .. } => Type :: from_value ( * pushval) . union ( types:: NilClass ) ,
1559- Insn :: DefinedIvar { .. } => types:: BasicObject ,
1559+ Insn :: DefinedIvar { pushval , .. } => Type :: from_value ( * pushval ) . union ( types:: NilClass ) ,
15601560 Insn :: GetConstantPath { .. } => types:: BasicObject ,
15611561 Insn :: ArrayMax { .. } => types:: BasicObject ,
15621562 Insn :: GetGlobal { .. } => types:: BasicObject ,
@@ -4989,12 +4989,41 @@ mod tests {
49894989 assert_snapshot ! ( hir_string( "test" ) , @r"
49904990 fn test@<compiled>:2:
49914991 bb0(v0:BasicObject):
4992- v5:BasicObject = DefinedIvar v0, :@foo
4992+ v5:StringExact|NilClass = DefinedIvar v0, :@foo
49934993 CheckInterrupts
49944994 Return v5
49954995 " ) ;
49964996 }
49974997
4998+ #[ test]
4999+ fn if_defined_ivar ( ) {
5000+ eval ( "
5001+ def test
5002+ if defined?(@foo)
5003+ 3
5004+ else
5005+ 4
5006+ end
5007+ end
5008+ " ) ;
5009+ assert_contains_opcode ( "test" , YARVINSN_definedivar ) ;
5010+ assert_snapshot ! ( hir_string( "test" ) , @r"
5011+ fn test@<compiled>:3:
5012+ bb0(v0:BasicObject):
5013+ v5:TrueClass|NilClass = DefinedIvar v0, :@foo
5014+ CheckInterrupts
5015+ v8:CBool = Test v5
5016+ IfFalse v8, bb1(v0)
5017+ v12:Fixnum[3] = Const Value(3)
5018+ CheckInterrupts
5019+ Return v12
5020+ bb1(v18:BasicObject):
5021+ v22:Fixnum[4] = Const Value(4)
5022+ CheckInterrupts
5023+ Return v22
5024+ " ) ;
5025+ }
5026+
49985027 #[ test]
49995028 fn defined ( ) {
50005029 eval ( "
0 commit comments