tova 0.2.9 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,10 +25,10 @@ export class PrimitiveType extends Type {
25
25
  if (target instanceof AnyType || target instanceof UnknownType) return true;
26
26
  if (target instanceof PrimitiveType) {
27
27
  if (this.name === target.name) return true;
28
- // Int -> Float widening is always allowed
28
+ // Int -> Float widening is always allowed (safe)
29
29
  if (this.name === 'Int' && target.name === 'Float') return true;
30
- // Float -> Int: allowed in non-strict (checked at call site)
31
- if (this.name === 'Float' && target.name === 'Int') return true;
30
+ // Float -> Int narrowing: NOT implicitly allowed at type level.
31
+ // The analyzer emits warning/error with conversion hint.
32
32
  }
33
33
  return false;
34
34
  }
@@ -66,7 +66,15 @@ export class AnyType extends Type {
66
66
 
67
67
  export class UnknownType extends Type {
68
68
  equals(other) { return other instanceof UnknownType; }
69
- isAssignableTo(_target) { return true; }
69
+ isAssignableTo(target) {
70
+ // In strict mode, unknown types are NOT assignable to concrete types
71
+ if (Type.strictMode) {
72
+ if (!target) return true;
73
+ if (target instanceof AnyType || target instanceof UnknownType) return true;
74
+ return false;
75
+ }
76
+ return true;
77
+ }
70
78
  toString() { return 'unknown'; }
71
79
  }
72
80
 
@@ -322,6 +330,10 @@ export class UnionType extends Type {
322
330
  }
323
331
  }
324
332
 
333
+ // ─── Strict Mode Flag ────────────────────────────────────
334
+
335
+ Type.strictMode = false; // Set to true by analyzer in --strict mode
336
+
325
337
  // ─── Singleton Caching ────────────────────────────────────
326
338
 
327
339
  Type.INT = new PrimitiveType('Int');
@@ -369,6 +381,10 @@ export function typeAnnotationToType(ann) {
369
381
  }
370
382
  case 'FunctionTypeAnnotation':
371
383
  return Type.FUNCTION;
384
+ case 'UnionTypeAnnotation': {
385
+ const members = ann.members.map(m => typeAnnotationToType(m) || Type.UNKNOWN);
386
+ return new UnionType(members);
387
+ }
372
388
  default:
373
389
  return null;
374
390
  }