Skip to content
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

Fix unseen Inner Class of Abstract Class #1459

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

olabusayoT
Copy link
Contributor

  • Scala 3.3.5 complains about not seeing the inner class Value of Enum, so we refactor to make Value a trait of an Enum companion object

DAFFODIL-2975

Copy link
Contributor

@mbeckerle mbeckerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, maybe some minor changes to simplify things?

// Special case for CalendarFirstDayOfWeek
//
case "Sunday" | "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" |
"Saturday" =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special case for CalendarFirstDayOfWeek feels a bit too specific for this generic trait. Maybe this is an exception that the property generator should do? Thinkkng about my above question, if the type parameter really isn't needed, maybe Enum.Value just becomes different variants of toString implementations for different kinds of enums, e.g.:

trait EnumValue extends EnumValueBase {
  override def toString = {
    /* current implementation with initial lower case unlessall upper
        case, without calendar first day of week exception */
  }
}
trait EnumValueSimple extends EnumValueBase {
  override def toString = getNameFromClass(this)
}

Most classes would just look like this to get the normal behavior:

sealed trait SeparatorSuppressionPolicy extends EnumValue

But CalendarFirstDayOfWeek would look like this:

sealed trait CalendarFirstDayOfWeek extends EnumValueSimple

I don't think we should make this change as partof this PR, modifying the generator for this one exception probably isn't worth it, but it might be worth opening a new cleanup ticket--this would probably be a good beginner issue to add new trait and modify the property generator to extends a different class depending on some exception list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created DAFFODIL-2983

@@ -133,6 +116,24 @@ abstract class Enum[A] extends EnumBase with Converter[String, A] {

def apply(name: String, context: ThrowsSDE): A
} // end class
object Enum {
trait Value[A] extends EnumValueBase { self: A =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the type parameter? To use the new Enum.Value a trait now needs to duplicate it's own trait name without much gain, I think?

The only thing the Value trait really provides now is a default implementation of the toString function, which doesn't depend on the type parameter.

I also wonder if instead of putting it in a Enum object, what if we just call it EnumValue? Similar to how Enum, EnumBase, EnumValueBase are their own things?

Then this just becomes:

sealed trait Foo extends EnumValue
object Foo extends Enum[Foo] {
  ...
}

Seems a bit cleaner and I think doesn't lose any type safety or functionality?

/* how to display data */
var representation: Representation.Value = Representation.Text
var representation: Enum.Value[Representation] =
Representation.Text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is the reason for needing the type parameter in Enum.Value, mentioned in a previous comment? Though, could this be changed to this:

var representation: Representation = Representation.Text

Representation is a trait that all representation enum values extend so I think this type is still accurate? It's maybe less clear that Representation is an enumeration value, but it's definitely cleaner. In fact, I think this is the only place where we use Foo.Value to reference our custom enum types since this is the only one you had to change.

- Scala 3.3.5 complains about not seeing the inner class Value of Enum, so we refactor to create an EnumValue trait

DAFFODIL-2975
@olabusayoT olabusayoT force-pushed the daf-2975-fix-enum-err branch from 63767a1 to 95f6b2b Compare March 27, 2025 17:57
@olabusayoT olabusayoT merged commit 4ae3eda into apache:main Mar 27, 2025
21 checks passed
@olabusayoT olabusayoT deleted the daf-2975-fix-enum-err branch March 27, 2025 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants