Skip to content

sui_v1.29.0_1719626141_ci

@tzakian tzakian tagged this 28 Jun 23:21
## Description 

Adds support for deprecation attributes to the source language:
```
#[deprecated]
<member>

#[deprecated(note = b"<string>")]
<member>
```

where `<member>` can be a module, constant, struct, enum, or function. 

Note that deprecation checking must be performed after typechecking
since we need to have methods resolved before determining whether the
call uses a deprecated function.

A couple things to note:
1. Accessing any member within a deprecated module, will raise a
deprecation warning. The one exception to this is access/calls within a
deprecated module -- in which case no warnings will be raised.

```move
#[deprecated]
module 0x42::m {
   public fun f() { }
   public fun call_f() { f(); } // no warning raised since internal access
}
```

```move
#[deprecated]
module 0x42::m {
   public fun f() { }
   public fun call_f() { f(); } // no warning raised since internal access
}

module 0x42::k {

 fun caller() { 0x42::m::f(); } // Will raise an error since an external access
}
```


2. Specific deprecations always override module deprecations, and they
will always raise a deprecation warning, even for internal accesses. In
particular:

```move
#[deprecated]
module 0x42::m {
   [deprecated(note = b"note")]
   public fun f() { }
   public fun call_f() { f(); } // warning will be raised with note "note"
}

module 0x42::k {
    fun caller() { 0x42::m::f(); } // warning will be raised with note "note"
}
```

3. Deprecations are grouped into single diagnostics -- one diagnostic
per `(deprecation, named_context)` pair where a named context can be
either a struct, enum, constant, or function. E.g., for the following
code
```move
module 0x42::m {
    #[deprecated]
    const A: u64 = 1;

    #[deprecated(note = b"use D instead")]
    const B: u64 = 2;

    #[deprecated(note = b"You should use E instead")]
    const C: u64 = 3;

    const D: u64 = 4;
    const E: u64 = 5;

    const Combo: u64 = {
        A + B + C + D + E + B
    };
}
```

Will produce the following warnings since:
```
warning[W04037]: use of deprecated constant
   ┌─ tests/move_2024/typing/deprecation_use_in_constants.move:15:9
   │
15 │         A + B + C + D + E + B
   │         ^ This constant is deprecated

warning[W04037]: use of deprecated constant
   ┌─ tests/move_2024/typing/deprecation_use_in_constants.move:15:13
   │
15 │         A + B + C + D + E + B
   │             ^               - Deprecated constant used again here
   │             │                
   │             This constant is deprecated: use D instead

warning[W04037]: use of deprecated constant
   ┌─ tests/move_2024/typing/deprecation_use_in_constants.move:15:17
   │
15 │         A + B + C + D + E + B
   │                 ^ This constant is deprecated: You should use E instead
```

Notice the warning for `B` has multiple labels -- one per usage of the
deprecated constant within the named context.

## Test plan 

Added new positive and negative tests for the deprecation behavior.
Assets 2
Loading