nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: 1Password/typeshare
Pull request #67 (2023-02-19 09:42:07)

scala: Generate type aliases when unsigned numbers are in generic types
Follow-up of #27 


Patch:
diff --git a/core/src/language/scala.rs b/core/src/language/scala.rs
index c140709..f1f67b4 100644
--- a/core/src/language/scala.rs
+++ b/core/src/language/scala.rs
@@ -8,6 +8,7 @@ use crate::{
 use itertools::Itertools;
 use joinery::JoinableIterator;
 use lazy_format::lazy_format;
+use std::ops::Deref;
 use std::{collections::HashMap, io::Write};
 
 /// All information needed for Scala type-code
@@ -411,6 +412,7 @@ impl Scala {
     }
 
     fn unsigned_integer_used(&mut self, data: &ParsedData) -> bool {
+        let types_in_aliases = data.aliases.iter().map(|f| f.r#type.clone()).collect_vec();
         let types_in_structs = data
             .structs
             .iter()
@@ -430,8 +432,19 @@ impl Scala {
                 })
             })
             .collect_vec();
-        itertools::concat(vec![types_in_structs, types_in_enum])
+        itertools::concat(vec![types_in_aliases, types_in_structs, types_in_enum])
             .iter()
+            .flat_map(|ty| match ty {
+                RustType::Generic { id: _, parameters } => parameters.clone(),
+                RustType::Special(SpecialRustType::Option(ty) | SpecialRustType::Vec(ty)) => {
+                    vec![ty.deref().clone()]
+                }
+                RustType::Special(SpecialRustType::HashMap(kty, vty)) => {
+                    vec![kty.deref().clone(), vty.deref().clone()]
+                }
+                RustType::Special(_) => vec![ty.clone()],
+                RustType::Simple { .. } => vec![],
+            })
             .any(|ty| {
                 matches!(
                     ty,


Test patch:
diff --git a/core/data/tests/can_generate_generic_enum/output.scala b/core/data/tests/can_generate_generic_enum/output.scala
index e16a6a1..f65d17b 100644
--- a/core/data/tests/can_generate_generic_enum/output.scala
+++ b/core/data/tests/can_generate_generic_enum/output.scala
@@ -3,6 +3,14 @@
  */
 package com.agilebits
 
+package object onepassword {
+
+type UByte = Byte
+type UShort = Short
+type UInt = Int
+type ULong = Int
+
+}
 package onepassword {
 
 case class StructUsingGenericEnum (
diff --git a/core/data/tests/test_optional_type_alias/output.scala b/core/data/tests/test_optional_type_alias/output.scala
index 2bc9d08..9358322 100644
--- a/core/data/tests/test_optional_type_alias/output.scala
+++ b/core/data/tests/test_optional_type_alias/output.scala
@@ -5,6 +5,11 @@ package com.agilebits
 
 package object onepassword {
 
+type UByte = Byte
+type UShort = Short
+type UInt = Int
+type ULong = Int
+
 type OptionalU32 = Option[UInt]
 
 type OptionalU16 = Option[UShort]