Repository: scalameta/scalameta
Pull request #3510 (2024-01-19 19:42:38)

Dialect: in privateCopy, don't copy if the same


Patch:
diff --git a/scalameta/dialects/shared/src/main/scala/scala/meta/Dialect.scala b/scalameta/dialects/shared/src/main/scala/scala/meta/Dialect.scala
index c3eb5f900..4e6085ecd 100644
--- a/scalameta/dialects/shared/src/main/scala/scala/meta/Dialect.scala
+++ b/scalameta/dialects/shared/src/main/scala/scala/meta/Dialect.scala
@@ -536,6 +536,65 @@ final class Dialect private[meta] (
       // NOTE(olafur): add the next parameter above this comment.
   ): Dialect = {
     val notForUnquote = unquoteType eq UnquoteType.None
+    val equivalent = notForUnquote && isEquivalentToInternal(
+      allowAtForExtractorVarargs = allowAtForExtractorVarargs,
+      allowCaseClassWithoutParameterList = allowCaseClassWithoutParameterList,
+      allowColonForExtractorVarargs = allowColonForExtractorVarargs,
+      allowEnums = allowEnums,
+      allowImplicitByNameParameters = allowImplicitByNameParameters,
+      allowInlineIdents = allowInlineIdents,
+      allowInlineMods = allowInlineMods,
+      allowLiteralTypes = allowLiteralTypes,
+      allowSpliceUnderscores = allowSpliceUnderscores,
+      allowToplevelTerms = allowToplevelTerms,
+      allowTrailingCommas = allowTrailingCommas,
+      allowTraitParameters = allowTraitParameters,
+      allowTypeLambdas = allowTypeLambdas,
+      allowViewBounds = allowViewBounds,
+      allowXmlLiterals = allowXmlLiterals,
+      allowNumericLiteralUnderscoreSeparators = allowNumericLiteralUnderscoreSeparators,
+      allowTryWithAnyExpr = allowTryWithAnyExpr,
+      allowGivenUsing = allowGivenUsing,
+      allowErasedDefs = allowErasedDefs,
+      allowExtensionMethods = allowExtensionMethods,
+      allowOpenClass = allowOpenClass,
+      allowToplevelStatements = allowToplevelStatements,
+      allowOpaqueTypes = allowOpaqueTypes,
+      allowExportClause = allowExportClause,
+      allowCommaSeparatedExtend = allowCommaSeparatedExtend,
+      allowEndMarker = allowEndMarker,
+      allowInterpolationDolarQuoteEscape = allowInterpolationDolarQuoteEscape,
+      allowSignificantIndentation = allowSignificantIndentation,
+      allowQuestionMarkAsTypeWildcard = allowQuestionMarkAsTypeWildcard,
+      allowTypeParamUnderscore = allowTypeParamUnderscore,
+      allowByNameRepeatedParameters = allowByNameRepeatedParameters,
+      allowLazyValAbstractValues = allowLazyValAbstractValues,
+      allowUpperCasePatternVarBinding = allowUpperCasePatternVarBinding,
+      allowDerives = allowDerives,
+      allowTypeInBlock = allowTypeInBlock,
+      allowPolymorphicFunctions = allowPolymorphicFunctions,
+      allowMatchAsOperator = allowMatchAsOperator,
+      allowTypeMatch = allowTypeMatch,
+      allowInfixMods = allowInfixMods,
+      allowSpliceAndQuote = allowSpliceAndQuote,
+      allowSymbolLiterals = allowSymbolLiterals,
+      allowDependentFunctionTypes = allowDependentFunctionTypes,
+      allowPostfixStarVarargSplices = allowPostfixStarVarargSplices,
+      allowAllTypedPatterns = allowAllTypedPatterns,
+      allowAsForImportRename = allowAsForImportRename,
+      allowStarWildcardImport = allowStarWildcardImport,
+      allowProcedureSyntax = allowProcedureSyntax,
+      allowDoWhile = allowDoWhile,
+      allowPlusMinusUnderscoreAsIdent = allowPlusMinusUnderscoreAsIdent,
+      allowUnderscoreAsTypePlaceholder = allowUnderscoreAsTypePlaceholder,
+      allowStarAsTypePlaceholder = allowStarAsTypePlaceholder,
+      allowGivenImports = allowGivenImports,
+      useInfixTypePrecedence = useInfixTypePrecedence,
+      allowInfixOperatorAfterNL = allowInfixOperatorAfterNL,
+      allowParamClauseInterleaving = allowParamClauseInterleaving,
+      allowFewerBraces = allowFewerBraces
+    )
+    if (equivalent) return this // RETURN!
     new Dialect(
       if (notForUnquote) null else this,
       unquoteType,


Test patch:
diff --git a/tests/shared/src/test/scala/scala/meta/tests/DialectSuite.scala b/tests/shared/src/test/scala/scala/meta/tests/DialectSuite.scala
index e12d7e4fc..07687898a 100644
--- a/tests/shared/src/test/scala/scala/meta/tests/DialectSuite.scala
+++ b/tests/shared/src/test/scala/scala/meta/tests/DialectSuite.scala
@@ -13,7 +13,7 @@ class DialectSuite extends FunSuite {
   }
 
   test("scala3 isEquivalentTo scala3copy") {
-    assertNotEquals(Scala3, scala3copy)
+    assertEquals(Scala3, scala3copy)
     assert(Scala3.isEquivalentTo(scala3copy))
   }
 
@@ -26,7 +26,7 @@ class DialectSuite extends FunSuite {
   test("scala3 isEquivalentTo scala3copy without deprecated") {
     val that = scala3copy.withAllowAndTypes(false)
     assertEquals(that, scala3copy)
-    assertNotEquals(that, Scala3)
+    assertEquals(that, Scala3)
     assert(Scala3.isEquivalentTo(that))
   }
 
@@ -45,7 +45,7 @@ class DialectSuite extends FunSuite {
   }
 
   test("scala3copy toString") {
-    assertEquals(scala3copy.toString, "Dialect()")
+    assertEquals(scala3copy.toString, "Scala33")
   }
 
   test("scala3 without indentation toString") {