-
-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support deprecated attribute in type constructors #3715
base: main
Are you sure you want to change the base?
support deprecated attribute in type constructors #3715
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking nice! I left a couple of comments inline
compiler-core/src/parse/error.rs
Outdated
ParseErrorType::UnknownAttributeRecordConstructor => ( | ||
"Variant attribute(s) are unknow.", | ||
vec!["Try `@deprecated`.".into()], | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather have an error that explicitly says that the attribute cannot be used on a variant for each of the attributes rather than a single error for all of those.
pub type Wibble {
@external(javascript, "", "")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This attribute cannot be used on a type variant
Wobble
}
Also I would not include that hint, it doesn't make much sense to suggest using deprecated
if I wrote an @external
or @internal
attribute
...rc/parse/snapshots/gleam_core__parse__tests__deprecation_attribute_on_all_type_variants.snap
Outdated
Show resolved
Hide resolved
Thank both!! |
When you're ready for review please un-draft this PR 💜 |
Is this ready for a review? :) |
Yes! :D |
Just so you know, merge commits are not allowed in this repository. You'll need to rebase before Louis will accept it |
9857f7c
to
836d5a4
Compare
Alright, that should be good. Sorry about that. I'll leave it up to y'all from here. |
One thing is missing is version tracking. If someone is using the deprecated attribute on a constructor we want to make sure the version in their gleam.toml is This would require adding a new variant gleam/compiler-core/src/type_/error.rs Lines 834 to 842 in 9ee71a1
|
5a06896
to
3828be4
Compare
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!! This is nearly ready to go. I've left some small comments
Finished! |
84845bb
to
33f9f03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fab! I've left some notes inline improving the wording of messages and making internal types more accurate. After that we're ready to merge! Thank you
compiler-core/src/analyse.rs
Outdated
@@ -878,6 +886,36 @@ impl<'a, A> ModuleAnalyzer<'a, A> { | |||
.parameters | |||
.clone(); | |||
|
|||
// check if all constructors are deprecated if so error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// check if all constructors are deprecated if so error | |
// Check if all constructors are deprecated if so error. |
compiler-core/src/analyse.rs
Outdated
.error(Error::AllVariantsConstructorDeprecated { location }); | ||
} | ||
|
||
// if any constructor record/varient is deprecated while |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if any constructor record/varient is deprecated while | |
// If any constructor record/varient is deprecated while |
compiler-core/src/analyse.rs
Outdated
.iter() | ||
.any(|record| record.deprecation.is_deprecated()) | ||
{ | ||
// report error on all variants attibuted with deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// report error on all variants attibuted with deprecated | |
// Report error on all variants attibuted with deprecated |
compiler-core/src/error.rs
Outdated
} | ||
"); | ||
Diagnostic { | ||
title: "Deprecating all variants of a type is not allowed.".into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: "Deprecating all variants of a type is not allowed.".into(), | |
title: "All variants of custom type deprecated.".into(), |
compiler-core/src/error.rs
Outdated
let text = String::from("Consider removing the deprecation attribute on the type's variant."); | ||
|
||
Diagnostic { | ||
title: "Deprecating variants of a type that is deprecated is not allowed".into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: "Deprecating variants of a type that is deprecated is not allowed".into(), | |
title: "Custom type already deprecated".into(), |
compiler-core/src/parse/error.rs
Outdated
@@ -398,6 +402,7 @@ pub enum ParseErrorType { | |||
ConstantRecordConstructorNoArguments, // const x = Record() | |||
TypeConstructorNoArguments, // let a : Int() | |||
TypeDefinitionNoArguments, // pub type Wibble() { ... } | |||
UnknownAttributeRecordConstructor, // an attribute was used that is not know for a custom type constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnknownAttributeRecordConstructor, // an attribute was used that is not know for a custom type constructor | |
UnknownAttributeRecordVariant // an attribute was used that is not know for a custom type variant |
compiler-core/src/type_/error.rs
Outdated
@@ -860,6 +880,7 @@ pub enum FeatureKind { | |||
AtInJavascriptModules, | |||
RecordUpdateVariantInference, | |||
RecordAccessVariantInference, | |||
ConstructorWithDeprecatedAnnotation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConstructorWithDeprecatedAnnotation, | |
VariantWithDeprecatedAnnotation, |
compiler-core/src/warning.rs
Outdated
@@ -1033,6 +1033,9 @@ See: https://tour.gleam.run/functions/pipelines/", | |||
FeatureKind::RecordAccessVariantInference => { | |||
"Field access on custom types when the variant is known was" | |||
} | |||
FeatureKind::ConstructorWithDeprecatedAnnotation => { | |||
"The constructor's `@deprecated` annotation was" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The constructor's `@deprecated` annotation was" | |
"Deprecating individual custom type variants was" |
compiler-core/src/type_/error.rs
Outdated
@@ -972,7 +994,9 @@ impl Error { | |||
} | |||
| Error::UseFnDoesntTakeCallback { location, .. } | |||
| Error::UseFnIncorrectArity { location, .. } | |||
| Error::BadName { location, .. } => location.start, | |||
| Error::BadName { location, .. } | |||
| Error::AllVariantsConstructorDeprecated { location } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Error::AllVariantsConstructorDeprecated { location } | |
| Error::AllVariantsDeprecated { location } |
compiler-core/src/type_/error.rs
Outdated
| Error::BadName { location, .. } => location.start, | ||
| Error::BadName { location, .. } | ||
| Error::AllVariantsConstructorDeprecated { location } | ||
| Error::VariantDeprecatedOnDeprecatedConstructor { location } => location.start, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Error::VariantDeprecatedOnDeprecatedConstructor { location } => location.start, | |
| Error::DeprecatedVariantOnDeprecatedType { location } => location.start, |
c1908bb
to
ec69f60
Compare
Hi @Wilbert-mad, you've force pushed to an older version of the code so there's now merge conflicts. Please rebase on main. Thank you |
ec69f60
to
f8280b9
Compare
Addressing: #3698