[SR-15051] Swift should suggest updating existing @available attribute when you use an insufficiently available declaration

Abierto
#57,378 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
cpp, swift

Línea de trabajo

Empieza en TypeCheckAvailability.cpp, en fixAvailabilityForDecl(), e inspecciona las pruebas de diagnóstico de availability existentes. Sigue el retorno anticipado para las declaraciones que tienen un atributo @available existente y cubre después los atributos simples, los atributos para varios OS y los atributos de formato largo. La tarea está terminada cuando los diagnósticos sugieren reemplazar la versión de availability insuficiente y pasan las pruebas relevantes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

availability compiler diagnostics quality fix-its good first issue improvement type checker
Previous ID SR-15051
Radar rdar://problem/81802673
Original Reporter @beccadax
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee mininny (JIRA)
Priority Medium

md5: 9db411fbe711e822a955f04325204e6d

Issue Description:

Currently, fixAvailabilityForDecl() in TypeCheckAvailability.cpp exits early if there is already an @available attribute on the declaration, with a comment noting work that should be done in the future:

/// Emit a diagnostic note and Fix-It to add an @available attribute
/// on the given declaration for the given version range.
static void fixAvailabilityForDecl(SourceRange ReferenceRange, const Decl *D,
                                   const VersionRange &RequiredRange,
                                   ASTContext &Context) {
  // ...irrelevant code omitted...

  if (getActiveAvailableAttribute(D, Context)) {
    // For QoI, in future should emit a fixit to update the existing attribute.
    return;
  }

Indeed, we should make this change. For instance, if you give the compiler this code:

@available(macOS 42, *) func foo() {}

@available(macOS 12, *) func bar() {
    foo()
}

Swift should emit a note with a fix-it replacing "macOS 12" with "macOS 42".

Your implementation, should you choose to commit it, should test not only this easy case with one simple @available attribute, but also cases with multiple OSes and long-form @available attributes. You will certainly need to update some existing tests; those might adequately cover this, but I'm not sure.

Lenguaje dominante
Swift
Estrellas
70.4k
Forks
10.8k
Merge medio
2 d 2 h
PR fusionados (30 d)
461

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de swiftlang/swift

Todos los issues de swiftlang/swift

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.