nyx-scanner 0.6.1

A multi-language static analysis tool for detecting security vulnerabilities
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
//! Condition lowering: CFG/SSA branch conditions → structured [`ConditionExpr`].
//!
//! This is the **only** module where `condition_text` is parsed. Everything
//! downstream operates on structured types with [`SsaValue`] keys.
//!
//! ## Lowering hierarchy (structured first, text fallback)
//!
//! 1. **Structural:** `condition_negated` (AST-level boolean)
//! 2. **Structural:** `condition_vars` (AST-extracted identifiers)
//! 3. **Structural:** compound decomposition (already handled by
//!    `build_condition_chain`, each leaf is a separate Block/Branch)
//! 4. **Structural:** `value_defs`, resolve var names to [`SsaValue`]s
//! 5. **Structural:** `const_values`, augment with known constants
//! 6. **Text fallback:** `condition_text`, parse comparison operator and
//!    literal operand. Necessary because individual comparisons are NOT
//!    decomposed into separate SSA operations (condition nodes → `Nop`).

#![allow(clippy::collapsible_if)]

use crate::cfg::NodeInfo;
use crate::ssa::const_prop::ConstLattice;
use crate::ssa::ir::{BlockId, SsaBody, SsaValue};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use std::collections::HashMap;

use super::domain::ConstValue;

// ── Operand ─────────────────────────────────────────────────────────────

/// An operand in a condition expression.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Operand {
    /// A resolved SSA value.
    Value(SsaValue),
    /// A constant literal extracted from the condition.
    Const(ConstValue),
    /// Could not resolve.
    Unknown,
}

// ── CompOp ──────────────────────────────────────────────────────────────

/// Comparison operator.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CompOp {
    Eq,
    Neq,
    Lt,
    Gt,
    Le,
    Ge,
}

impl CompOp {
    /// Flip the operator (swap operands): `a < b` becomes `b > a`.
    pub fn flip(self) -> Self {
        match self {
            Self::Lt => Self::Gt,
            Self::Gt => Self::Lt,
            Self::Le => Self::Ge,
            Self::Ge => Self::Le,
            other => other, // Eq, Neq are symmetric
        }
    }

    /// Negate the operator: `<` becomes `>=`.
    pub fn negate(self) -> Self {
        match self {
            Self::Eq => Self::Neq,
            Self::Neq => Self::Eq,
            Self::Lt => Self::Ge,
            Self::Ge => Self::Lt,
            Self::Gt => Self::Le,
            Self::Le => Self::Gt,
        }
    }
}

// ── ConditionExpr ───────────────────────────────────────────────────────

/// Structured condition expression with SSA-resolved operands.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConditionExpr {
    /// `lhs op rhs`, e.g., `x > 5`, `x == y`.
    Comparison {
        lhs: Operand,
        op: CompOp,
        rhs: Operand,
    },
    /// Null check: `x == null` / `x != null`.
    NullCheck { var: SsaValue, is_null: bool },
    /// Type check: `typeof x === "string"`.
    TypeCheck {
        var: SsaValue,
        type_name: String,
        positive: bool,
    },
    /// Boolean truthiness test: `if (x)`.
    BoolTest { var: SsaValue },
    /// Could not parse or resolve, conservatively no refinement.
    Unknown,
}

impl ConditionExpr {
    /// Structurally negate a condition expression.
    pub fn negate(&self) -> Self {
        match self {
            Self::Comparison { lhs, op, rhs } => Self::Comparison {
                lhs: lhs.clone(),
                op: op.negate(),
                rhs: rhs.clone(),
            },
            Self::NullCheck { var, is_null } => Self::NullCheck {
                var: *var,
                is_null: !is_null,
            },
            Self::TypeCheck {
                var,
                type_name,
                positive,
            } => Self::TypeCheck {
                var: *var,
                type_name: type_name.clone(),
                positive: !positive,
            },
            // BoolTest negation: handled by the solver using polarity
            Self::BoolTest { .. } | Self::Unknown => self.clone(),
        }
    }
}

// ── Condition lowering ──────────────────────────────────────────────────

/// Lower a branch condition from CFG metadata to a structured
/// [`ConditionExpr`] with SSA-resolved operands.
///
/// Uses structured metadata first (condition_negated, condition_vars,
/// value_defs, const_values), falling back to condition_text parsing
/// for comparison operators and literals.
pub fn lower_condition(
    cond_info: &NodeInfo,
    ssa: &SsaBody,
    branch_block: BlockId,
    const_values: Option<&HashMap<SsaValue, ConstLattice>>,
) -> ConditionExpr {
    let text = match cond_info.condition_text.as_deref() {
        Some(t) if !t.is_empty() => t,
        _ => return ConditionExpr::Unknown,
    };

    if cond_info.condition_vars.is_empty() {
        return ConditionExpr::Unknown;
    }

    // Step 1: Resolve condition variable names to SsaValues
    let resolved = resolve_condition_vars(&cond_info.condition_vars, ssa, branch_block);

    // Step 2: Build a name→SsaValue lookup
    let var_lookup: HashMap<&str, SsaValue> = resolved
        .iter()
        .map(|(name, val)| (name.as_str(), *val))
        .collect();

    // Step 3: Check if any resolved values have known constants
    let const_lookup: HashMap<SsaValue, ConstValue> = if let Some(cv) = const_values {
        resolved
            .iter()
            .filter_map(|(_, v)| {
                cv.get(v)
                    .and_then(ConstValue::from_const_lattice)
                    .map(|c| (*v, c))
            })
            .collect()
    } else {
        HashMap::new()
    };

    // Step 4: Try structured patterns, then text fallback
    let lower = text.to_ascii_lowercase();

    let expr = try_lower_null_check(text, &lower, &var_lookup)
        .or_else(|| try_lower_type_check(text, &lower, &var_lookup))
        .or_else(|| try_lower_comparison(text, &var_lookup, &const_lookup))
        .unwrap_or_else(|| {
            // Fallback: if exactly one condition_var, treat as BoolTest
            if resolved.len() == 1 {
                ConditionExpr::BoolTest { var: resolved[0].1 }
            } else {
                ConditionExpr::Unknown
            }
        });

    // Apply structural negation from condition_negated
    if cond_info.condition_negated {
        expr.negate()
    } else {
        expr
    }
}

/// Lower a branch condition using var_stacks from SSA construction.
///
/// Called during SSA lowering when the full [`SsaBody`] is not yet available.
/// Resolves variables via `var_stacks[name].last()` (the current reaching
/// definition) instead of scanning `value_defs`. Does not use `const_values`
/// (unavailable at lowering time); constants are seeded into [`crate::constraint::PathEnv`]
/// separately via `seed_from_optimization`.
pub fn lower_condition_with_stacks(
    cond_info: &NodeInfo,
    var_stacks: &HashMap<String, Vec<SsaValue>>,
) -> ConditionExpr {
    let text = match cond_info.condition_text.as_deref() {
        Some(t) if !t.is_empty() => t,
        _ => return ConditionExpr::Unknown,
    };

    if cond_info.condition_vars.is_empty() {
        return ConditionExpr::Unknown;
    }

    // Resolve via var_stacks: each var's current reaching definition
    let resolved: Vec<(String, SsaValue)> = cond_info
        .condition_vars
        .iter()
        .filter_map(|name| {
            var_stacks
                .get(name)
                .and_then(|stack| stack.last().copied())
                .map(|v| (name.clone(), v))
        })
        .collect();

    if resolved.is_empty() {
        return ConditionExpr::Unknown;
    }

    let var_lookup: HashMap<&str, SsaValue> = resolved
        .iter()
        .map(|(name, val)| (name.as_str(), *val))
        .collect();

    // No const_values at lowering time, empty lookup
    let const_lookup: HashMap<SsaValue, super::domain::ConstValue> = HashMap::new();

    let lower = text.to_ascii_lowercase();

    let expr = try_lower_null_check(text, &lower, &var_lookup)
        .or_else(|| try_lower_type_check(text, &lower, &var_lookup))
        .or_else(|| try_lower_comparison(text, &var_lookup, &const_lookup))
        .unwrap_or_else(|| {
            if resolved.len() == 1 {
                ConditionExpr::BoolTest { var: resolved[0].1 }
            } else {
                ConditionExpr::Unknown
            }
        });

    if cond_info.condition_negated {
        expr.negate()
    } else {
        expr
    }
}

// ── Variable resolution ─────────────────────────────────────────────────

/// Resolve condition variable names to their reaching SSA definitions.
///
/// Uses `ssa.value_defs` (SSA structural metadata) to find definitions,
/// not instruction body scanning. For each variable name:
///
/// 1. Find all definitions with that name via `value_defs`.
/// 2. Prefer the definition in the current block (reaching def at block end).
/// 3. If no def in current block, take the highest-indexed def whose
///    block precedes the current block (approximate dominator walk).
pub fn resolve_condition_vars(
    vars: &[String],
    ssa: &SsaBody,
    block: BlockId,
) -> SmallVec<[(String, SsaValue); 4]> {
    let mut result = SmallVec::new();

    for var_name in vars {
        if let Some(val) = resolve_single_var(var_name, ssa, block) {
            result.push((var_name.clone(), val));
        }
    }

    result
}

fn resolve_single_var(var_name: &str, ssa: &SsaBody, block: BlockId) -> Option<SsaValue> {
    let mut best_in_block: Option<SsaValue> = None;
    let mut best_outside: Option<SsaValue> = None;

    for (idx, vd) in ssa.value_defs.iter().enumerate() {
        if vd.var_name.as_deref() != Some(var_name) {
            continue;
        }
        let v = SsaValue(idx as u32);
        if vd.block == block {
            // Prefer highest index in current block (last definition)
            best_in_block = Some(match best_in_block {
                Some(existing) if existing.0 > v.0 => existing,
                _ => v,
            });
        } else {
            // Outside current block: take highest index (approximate)
            best_outside = Some(match best_outside {
                Some(existing) if existing.0 > v.0 => existing,
                _ => v,
            });
        }
    }

    best_in_block.or(best_outside)
}

// ── Null check lowering ─────────────────────────────────────────────────

fn try_lower_null_check(
    text: &str,
    lower: &str,
    var_lookup: &HashMap<&str, SsaValue>,
) -> Option<ConditionExpr> {
    // Patterns: "x == null", "x === null", "x != null", "x !== null"
    //           "x is None", "x is not None", "x == nil", "x != nil"

    let is_null;
    let var_name;

    // Python "is None" / "is not None"
    if lower.contains(" is not none") {
        is_null = false;
        var_name = extract_before(text, " is not ");
    } else if lower.contains(" is none") {
        is_null = true;
        var_name = extract_before(text, " is ");
    }
    // JS/TS/Java null checks
    else if let Some((lhs, rhs, negated)) = try_split_equality(text) {
        let lhs_t = lhs.trim();
        let rhs_t = rhs.trim();
        let lhs_lower = lhs_t.to_ascii_lowercase();
        let rhs_lower = rhs_t.to_ascii_lowercase();

        let (null_side, var_side) =
            if lhs_lower == "null" || lhs_lower == "nil" || lhs_lower == "none" {
                (true, rhs_t)
            } else if rhs_lower == "null" || rhs_lower == "nil" || rhs_lower == "none" {
                (true, lhs_t)
            } else {
                return None; // Not a null check
            };

        if !null_side {
            return None;
        }
        var_name = Some(var_side);
        is_null = !negated;
    } else {
        return None;
    }

    let var_name = var_name?;
    let var_name_trimmed = var_name.trim();
    let ssa_val = var_lookup.get(var_name_trimmed)?;
    Some(ConditionExpr::NullCheck {
        var: *ssa_val,
        is_null,
    })
}

// ── Type check lowering ─────────────────────────────────────────────────

fn try_lower_type_check(
    text: &str,
    lower: &str,
    var_lookup: &HashMap<&str, SsaValue>,
) -> Option<ConditionExpr> {
    // Pattern: "typeof x === 'string'"
    if lower.starts_with("typeof ") {
        let rest = &text[7..]; // skip "typeof "
        let (lhs, rhs, negated) = try_split_equality(rest)?;
        let var_part = lhs.trim();
        let type_part = rhs.trim();
        // Strip quotes from type
        let type_name = strip_quotes(type_part)?;
        let ssa_val = var_lookup.get(var_part)?;
        return Some(ConditionExpr::TypeCheck {
            var: *ssa_val,
            type_name: type_name.to_string(),
            positive: !negated,
        });
    }

    // Pattern: "isinstance(x, int)" (Python)
    if lower.starts_with("isinstance(") && lower.ends_with(')') {
        let inner = &text[11..text.len() - 1]; // strip isinstance( ... )
        let comma = inner.find(',')?;
        let var_part = inner[..comma].trim();
        let type_part = inner[comma + 1..].trim();
        let ssa_val = var_lookup.get(var_part)?;
        return Some(ConditionExpr::TypeCheck {
            var: *ssa_val,
            type_name: type_part.to_string(),
            positive: true,
        });
    }

    // Pattern: PHP "is_numeric(x)", "is_string(x)", etc.
    if lower.starts_with("is_") && lower.ends_with(')') {
        if let Some(paren) = text.find('(') {
            let type_part = &text[3..paren]; // "numeric", "string", etc.
            let var_part = text[paren + 1..text.len() - 1].trim();
            let ssa_val = var_lookup.get(var_part)?;
            return Some(ConditionExpr::TypeCheck {
                var: *ssa_val,
                type_name: type_part.to_string(),
                positive: true,
            });
        }
    }

    // Pattern: "x instanceof String" (Java/TypeScript)
    if let Some(pos) = lower.find(" instanceof ") {
        let var_part = text[..pos].trim();
        let type_part = text[pos + " instanceof ".len()..].trim();
        if let Some(ssa_val) = var_lookup.get(var_part) {
            return Some(ConditionExpr::TypeCheck {
                var: *ssa_val,
                type_name: type_part.to_string(),
                positive: true,
            });
        }
    }

    // Pattern: "x.is_a?(Integer)" / "x.kind_of?(Integer)" (Ruby)
    for method in &[".is_a?(", ".kind_of?("] {
        if let Some(dot_pos) = lower.find(method) {
            let var_part = text[..dot_pos].trim();
            let after = dot_pos + method.len();
            if let Some(close) = text[after..].find(')') {
                let type_part = text[after..after + close].trim();
                if let Some(ssa_val) = var_lookup.get(var_part) {
                    return Some(ConditionExpr::TypeCheck {
                        var: *ssa_val,
                        type_name: type_part.to_string(),
                        positive: true,
                    });
                }
            }
        }
    }

    None
}

// ── Comparison lowering ─────────────────────────────────────────────────

fn try_lower_comparison(
    text: &str,
    var_lookup: &HashMap<&str, SsaValue>,
    const_lookup: &HashMap<SsaValue, ConstValue>,
) -> Option<ConditionExpr> {
    // Find comparison operator (longest first to avoid prefix conflicts)
    let operators = ["===", "!==", "==", "!=", ">=", "<=", ">", "<"];
    let mut found_op = None;
    let mut found_pos = 0;
    let mut found_len = 0;

    for op_str in &operators {
        if let Some(pos) = text.find(op_str) {
            // Avoid matching inside strings
            if found_op.is_none() || op_str.len() > found_len {
                found_op = Some(*op_str);
                found_pos = pos;
                found_len = op_str.len();
            }
        }
    }

    let op_str = found_op?;
    let lhs = text[..found_pos].trim();
    let rhs = text[found_pos + found_len..].trim();

    let op = match op_str {
        "===" | "==" => CompOp::Eq,
        "!==" | "!=" => CompOp::Neq,
        "<" => CompOp::Lt,
        ">" => CompOp::Gt,
        "<=" => CompOp::Le,
        ">=" => CompOp::Ge,
        _ => return None,
    };

    // Resolve operands
    let lhs_op = resolve_operand(lhs, var_lookup, const_lookup);
    let rhs_op = resolve_operand(rhs, var_lookup, const_lookup);

    // Need at least one Value operand
    // If both unknown, nothing useful
    if matches!(&lhs_op, Operand::Unknown) && matches!(&rhs_op, Operand::Unknown) {
        return None;
    }

    Some(ConditionExpr::Comparison {
        lhs: lhs_op,
        op,
        rhs: rhs_op,
    })
}

fn resolve_operand(
    text: &str,
    var_lookup: &HashMap<&str, SsaValue>,
    const_lookup: &HashMap<SsaValue, ConstValue>,
) -> Operand {
    // Try as variable first
    if let Some(&ssa_val) = var_lookup.get(text) {
        // Check if we know its constant value (structured knowledge)
        if let Some(cv) = const_lookup.get(&ssa_val) {
            return Operand::Const(cv.clone());
        }
        return Operand::Value(ssa_val);
    }

    // Try as literal
    if let Some(cv) = ConstValue::parse_literal(text) {
        return Operand::Const(cv);
    }

    // Try stripping quotes (for string literals inside conditions)
    if let Some(s) = strip_quotes(text) {
        return Operand::Const(ConstValue::Str(s.to_string()));
    }

    Operand::Unknown
}

// ── Text parsing helpers ────────────────────────────────────────────────

/// Try to split on an equality/inequality operator.
/// Returns (lhs, rhs, is_negated).
fn try_split_equality(text: &str) -> Option<(&str, &str, bool)> {
    // Try longest operators first
    for (op, negated) in &[("!==", true), ("===", false), ("!=", true), ("==", false)] {
        if let Some(pos) = text.find(op) {
            return Some((&text[..pos], &text[pos + op.len()..], *negated));
        }
    }
    None
}

/// Extract the text before a case-insensitive marker.
fn extract_before<'a>(text: &'a str, marker: &str) -> Option<&'a str> {
    let lower = text.to_ascii_lowercase();
    let marker_lower = marker.to_ascii_lowercase();
    lower.find(&marker_lower).map(|pos| &text[..pos])
}

/// Strip surrounding quotes from a string.
fn strip_quotes(text: &str) -> Option<&str> {
    let t = text.trim();
    if t.len() >= 2 {
        if (t.starts_with('"') && t.ends_with('"'))
            || (t.starts_with('\'') && t.ends_with('\''))
            || (t.starts_with('`') && t.ends_with('`'))
        {
            return Some(&t[1..t.len() - 1]);
        }
    }
    None
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::cfg::{NodeInfo, StmtKind};
    use crate::ssa::ir::{BlockId, SsaBlock, SsaBody, SsaValue, Terminator, ValueDef};
    use petgraph::graph::NodeIndex;
    use smallvec::SmallVec;

    /// Helper: build a minimal SsaBody with value_defs for the given variable
    /// names, all assigned to block 0.
    fn make_ssa_body(var_names: &[&str]) -> SsaBody {
        let value_defs: Vec<ValueDef> = var_names
            .iter()
            .enumerate()
            .map(|(i, name)| ValueDef {
                var_name: Some(name.to_string()),
                cfg_node: NodeIndex::new(i),
                block: BlockId(0),
            })
            .collect();

        SsaBody {
            blocks: vec![SsaBlock {
                id: BlockId(0),
                phis: vec![],
                body: vec![],
                terminator: Terminator::Return(None),
                preds: SmallVec::new(),
                succs: SmallVec::new(),
            }],
            entry: BlockId(0),
            value_defs,
            cfg_node_map: std::collections::HashMap::new(),
            exception_edges: vec![],
            field_interner: crate::ssa::ir::FieldInterner::default(),
            field_writes: std::collections::HashMap::new(),

            synthetic_externals: std::collections::HashSet::new(),
        }
    }

    /// Helper: build a minimal NodeInfo for a condition.
    fn make_cond_info(text: &str, vars: &[&str]) -> NodeInfo {
        NodeInfo {
            kind: StmtKind::If,
            condition_text: Some(text.to_string()),
            condition_vars: vars.iter().map(|v| v.to_string()).collect(),
            ..Default::default()
        }
    }

    // ── instanceof pattern ───────────────────────────────────────────────

    #[test]
    fn lower_instanceof_string() {
        let ssa = make_ssa_body(&["x"]);
        let info = make_cond_info("x instanceof String", &["x"]);
        let expr = lower_condition(&info, &ssa, BlockId(0), None);
        match expr {
            ConditionExpr::TypeCheck {
                var,
                type_name,
                positive,
            } => {
                assert_eq!(var, SsaValue(0));
                assert_eq!(type_name, "String");
                assert!(positive);
            }
            other => panic!("expected TypeCheck, got {:?}", other),
        }
    }

    // ── .is_a? pattern (Ruby) ────────────────────────────────────────────

    #[test]
    fn lower_is_a_integer() {
        let ssa = make_ssa_body(&["user_id"]);
        let info = make_cond_info("user_id.is_a?(Integer)", &["user_id"]);
        let expr = lower_condition(&info, &ssa, BlockId(0), None);
        match expr {
            ConditionExpr::TypeCheck {
                var,
                type_name,
                positive,
            } => {
                assert_eq!(var, SsaValue(0));
                assert_eq!(type_name, "Integer");
                assert!(positive);
            }
            other => panic!("expected TypeCheck, got {:?}", other),
        }
    }

    // ── .kind_of? pattern (Ruby) ─────────────────────────────────────────

    #[test]
    fn lower_kind_of_float() {
        let ssa = make_ssa_body(&["x"]);
        let info = make_cond_info("x.kind_of?(Float)", &["x"]);
        let expr = lower_condition(&info, &ssa, BlockId(0), None);
        match expr {
            ConditionExpr::TypeCheck {
                var,
                type_name,
                positive,
            } => {
                assert_eq!(var, SsaValue(0));
                assert_eq!(type_name, "Float");
                assert!(positive);
            }
            other => panic!("expected TypeCheck, got {:?}", other),
        }
    }
}