Skip to content

Commit 72eeacc

Browse files
committed
Fix ?
1 parent 9206a29 commit 72eeacc

File tree

5 files changed

+16
-31
lines changed

5 files changed

+16
-31
lines changed

conformance/third_party/conformance.exp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6383,28 +6383,6 @@
63836383
}
63846384
],
63856385
"generics_self_usage.py": [
6386-
{
6387-
"code": -2,
6388-
"column": 16,
6389-
"concise_description": "Returned type `ReturnsSelf` is not assignable to declared return type `Self@ReturnsSelf`",
6390-
"description": "Returned type `ReturnsSelf` is not assignable to declared return type `Self@ReturnsSelf`",
6391-
"line": 15,
6392-
"name": "bad-return",
6393-
"severity": "error",
6394-
"stop_column": 22,
6395-
"stop_line": 15
6396-
},
6397-
{
6398-
"code": -2,
6399-
"column": 16,
6400-
"concise_description": "Returned type `ReturnsSelf` is not assignable to declared return type `Self@ReturnsSelf`",
6401-
"description": "Returned type `ReturnsSelf` is not assignable to declared return type `Self@ReturnsSelf`",
6402-
"line": 18,
6403-
"name": "bad-return",
6404-
"severity": "error",
6405-
"stop_column": 22,
6406-
"stop_line": 18
6407-
},
64086386
{
64096387
"code": -2,
64106388
"column": 14,

conformance/third_party/conformance.result

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@
117117
"generics_self_basic.py": [],
118118
"generics_self_protocols.py": [],
119119
"generics_self_usage.py": [
120-
"Line 82: Expected 1 errors",
121-
"Line 15: Unexpected errors ['Returned type `ReturnsSelf` is not assignable to declared return type `Self@ReturnsSelf`']",
122-
"Line 18: Unexpected errors ['Returned type `ReturnsSelf` is not assignable to declared return type `Self@ReturnsSelf`']"
120+
"Line 82: Expected 1 errors"
123121
],
124122
"generics_syntax_compatibility.py": [],
125123
"generics_syntax_declarations.py": [],

conformance/third_party/results.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"pass": 123,
44
"fail": 15,
55
"pass_rate": 0.89,
6-
"differences": 42,
6+
"differences": 40,
77
"passing": [
88
"aliases_explicit.py",
99
"aliases_newtype.py",
@@ -141,7 +141,7 @@
141141
"generics_basic.py": 3,
142142
"generics_paramspec_components.py": 1,
143143
"generics_scoping.py": 4,
144-
"generics_self_usage.py": 3,
144+
"generics_self_usage.py": 1,
145145
"generics_typevartuple_basic.py": 1,
146146
"protocols_modules.py": 1,
147147
"qualifiers_final_annotation.py": 3

pyrefly/lib/alt/call.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,13 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
796796
}
797797
if let Some(mut ret) = dunder_new_ret {
798798
ret.subst_mut(&cls.targs().substitution_map());
799-
ret
799+
if constructor_kind == ConstructorKind::TypeOfSelf
800+
&& let Type::ClassType(ret_cls) = &ret
801+
{
802+
self.heap.mk_self_type(ret_cls.clone())
803+
} else {
804+
ret
805+
}
800806
} else if constructor_kind == ConstructorKind::TypeOfSelf {
801807
self.heap.mk_self_type(cls)
802808
} else {
@@ -966,6 +972,10 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
966972
context,
967973
hint,
968974
);
975+
eprintln!(
976+
"Constructed type: {}",
977+
self.for_display(constructed_type.clone())
978+
);
969979
// Override the constructed type with the quantified bound if
970980
// this class is being called via a quantified type with a class
971981
// bound, to allow calls on TypeVars with class bounds to work

pyrefly/lib/test/typing_self.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,15 @@ class B(A[Y1 | Y2], Generic[Y1, Y2]):
312312
);
313313

314314
testcase!(
315-
bug = "should not error",
316315
test_self_return_in_classmethod,
317316
r#"
318317
from typing import Self
319318
class C:
320319
@classmethod
321320
def bar(cls) -> Self:
322-
return cls(1) # E: Returned type `C` is not assignable to declared return type `Self@C`
321+
return cls(1)
323322
324323
def __new__(cls, value: int) -> Self: # Accepted
325-
return cls(1) # E: Returned type `C` is not assignable to declared return type `Self@C`
324+
return cls(1)
326325
"#,
327326
);

0 commit comments

Comments
 (0)