Repository navigation
Commit bdff6df
committed
fix: a field's value can arrive through another instance of its class
class Cell:
def __init__(self, v: int) -> None:
self.nxt = None
def chain(self, other: "Cell") -> None:
other.nxt = self
# attribute value '!py.contract<"Cell">' is not assignable to field
# '!py.literal<None>'
-- the way every linked structure links. The field walk read only `self.<name>`
targets, so a method assigning through ANOTHER instance of its own class said
nothing about the field, and the None the constructor gave it stood.
⛔ Only when the target's owner infers to THIS class: through anything else the
target names another class's field, which this walk does not own and must not
decide.
⛔ And `self` itself had to be bound in that pre-pass scope. It is the one
parameter with no annotation to read, so `collectInitArgTypes` skips it -- and
`other.nxt = self` therefore typed as nothing at all, which is the same store
by the other end.
⛔ `object` IS THE PRE-PASS SAYING IT DOES NOT KNOW, and it was being taken as
an answer: a store this walk cannot type turned a NoneType field into
`object | None`, which is a field whose reads carry nothing and whose
diagnostic then names the wrong thing. A store that types as `object` now
contributes nothing, which is what it knows.
Claude-Session: https://claude.ai/code/session_015SCJyt2UgUigFCdKuBfizX1 parent acdb454 commit bdff6df
3 files changed
Lines changed: 59 additions & 1 deletion
File tree
- src/lython/emitter/lib
- tests/golden/cases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2759 | 2759 | | |
2760 | 2760 | | |
2761 | 2761 | | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
2762 | 2769 | | |
2763 | 2770 | | |
2764 | 2771 | | |
| |||
2812 | 2819 | | |
2813 | 2820 | | |
2814 | 2821 | | |
2815 | | - | |
| 2822 | + | |
2816 | 2823 | | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
2817 | 2848 | | |
2818 | 2849 | | |
2819 | 2850 | | |
| |||
2868 | 2899 | | |
2869 | 2900 | | |
2870 | 2901 | | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
2871 | 2911 | | |
2872 | 2912 | | |
2873 | 2913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
48 | 65 | | |
49 | 66 | | |
50 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
0 commit comments