stc icon indicating copy to clipboard operation
stc copied to clipboard

Use correct error code for readonly properties

Open kdy1 opened this issue 2 years ago • 1 comments

https://github.com/dudykr/stc/blob/d50b685dd80aaa0ca4227551bb9cd26af0fd7af4/crates/stc_ts_type_checker/tests/conformance/types/intersection/intersectionTypeReadonly.ts#L17

This should fail with TS2540, but currently stc fails with

TS2339

  x context: tried to access property of an object to calculate type of a member expression
  | context: tried to access property of an object (Base#6917;
  | Member as {
  |     readonly value: number;
  | };, id_ctx = Var)
  | Prop=Normal { span: Span { lo: BytePos(276), hi: BytePos(281), ctxt: #0 }, sym: Atom('value' type=inline) }
  | NoSuchProperty {
  |     span: Span {
  |         lo: BytePos(
  |             271,
  |         ),
  |         hi: BytePos(
  |             281,
  |         ),
  |         ctxt: #0,
  |     },
  |     obj: Some(
  |         Arc(
  |             Freezed {
  |                 ty: Interface(
  |                     Interface {
  |                         span: Span {
  |                             lo: BytePos(
  |                                 271,
  |                             ),
  |                             hi: BytePos(
  |                                 275,
  |                             ),
  |                             ctxt: #0,
  |                         },
  |                         name: Base#6917,
  |                         type_params: None,
  |                         extends: [],
  |                         body: [
  |                             Property(
  |                                 PropertySignature {
  |                                     span: Span {
  |                                         lo: BytePos(
  |                                             24,
  |                                         ),
  |                                         hi: BytePos(
  |                                             47,
  |                                         ),
  |                                         ctxt: #0,
  |                                     },
  |                                     accessibility: None,
  |                                     readonly: true,
  |                                     key: Normal {
  |                                         span: Span {
  |                                             lo: BytePos(
  |                                                 33,
  |                                             ),
  |                                             hi: BytePos(
  |                                                 38,
  |                                             ),
  |                                             ctxt: #0,
  |                                         },
  |                                         sym: Atom('value' type=inline),
  |                                     },
  |                                     optional: false,
  |                                     params: [],
  |                                     type_ann: Some(
  |                                         Keyword(
  |                                             KeywordType {
  |                                                 span: Span {
  |                                                     lo: BytePos(
  |                                                         40,
  |                                                     ),
  |                                                     hi: BytePos(
  |                                                         46,
  |                                                     ),
  |                                                     ctxt: #0,
  |                                                 },
  |                                                 kind: TsNumberKeyword,
  |                                                 metadata: KeywordTypeMetadata {
  |                                                     common: CommonTypeMetadata {
  |                                                         implicit: false,
  |                                                         infected_by_this_in_object_literal: false,
  |                                                         prevent_converting_to_children: false,
  |                                                         no_expand: false,
  |                                                         ignore_no_expand: false,
  |                                                         contains_infer_type: false,
  |                                                         prevent_complex_simplification: false,
  |                                                         resolved_from_var: false,
  |                                                         prevent_generalization: false,
  |                                                         prevent_tuple_to_array: false,
  |                                                     },
  |                                                 },
  |                                             },
  |                                         ),
  |                                     ),
  |                                     type_params: None,
  |                                     metadata: TypeElMetadata {
  |                                         has_default: false,
  |                                     },
  |                                     accessor: Accessor {
  |                                         getter: false,
  |                                         setter: false,
  |                                     },
  |                                 },
  |                             ),
  |                         ],
  |                         metadata: InterfaceMetadata {
  |                             common: CommonTypeMetadata {
  |                                 implicit: false,
  |                                 infected_by_this_in_object_literal: false,
  |                                 prevent_converting_to_children: false,
  |                                 no_expand: false,
  |                                 ignore_no_expand: false,
  |                                 contains_infer_type: false,
  |                                 prevent_complex_simplification: false,
  |                                 resolved_from_var: true,
  |                                 prevent_generalization: false,
  |                                 prevent_tuple_to_array: false,
  |                             },
  |                         },
  |                     },
  |                 ),
  |             },
  |         ),
  |     ),
  |     prop: Some(
  |         Normal {
  |             span: Span {
  |                 lo: BytePos(
  |                     276,
  |                 ),
  |                 hi: BytePos(
  |                     281,
  |                 ),
  |                 ctxt: #0,
  |             },
  |             sym: Atom('value' type=inline),
  |         },
  |     ),
  | }
    ,-[$DIR/tests/conformance/types/intersection/intersectionTypeReadonly.ts:17:1]
 17 | base.value = 12 // error, lhs can't be a readonly property
    : ^^^^^^^^^^
    `----

kdy1 avatar Dec 06 '22 09:12 kdy1

I think the range overlaps with #398 I'll work on it.

moved #439

sunrabbit123 avatar Dec 20 '22 03:12 sunrabbit123

resolved it #1043

sunrabbit123 avatar Jun 04 '23 14:06 sunrabbit123