nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: vaskoz/dailycodingproblem-go
Pull request #647 (2019-07-06 13:01:53)

day 142 fix: Thank you Alex! @alexfjw
Thanks to @alexfjw for pointing out a test case that fails for my solution. 🙇 
https://github.com/vaskoz/dailycodingproblem-go/issues/297#issuecomment-508896291

Specifically, `*(` failed in my solution because it didn't account for the position for the wildcard being before the open brace.

My new solution calculates the number of opening braces in two different ways. First, assuming that wildcards are just opening braces. Second, assuming that wildcards are just closing braces.

If wildcard closing braces goes negative, assuming they're empty strings instead.

Unfortunately, this correct solution is twice as slow as my first version.
```
goos: darwin
goarch: amd64
pkg: github.com/vaskoz/dailycodingproblem-go/day142
BenchmarkWildcardParens-12    	   50000	     25021 ns/op
```
versus
```
goos: darwin
goarch: amd64
pkg: github.com/vaskoz/dailycodingproblem-go/day142
BenchmarkWildcardParens-12    	  100000	     12708 ns/op
```


Patch:
diff --git a/day142/problem.go b/day142/problem.go
index 41a1b76..30c6fa0 100644
--- a/day142/problem.go
+++ b/day142/problem.go
@@ -3,24 +3,32 @@ package day142
 // WildcardParens answers if the parens are balanced.
 // This includes a wildcard character '*' that can be either paren
 // or an empty string.
+// Implementation note: counts opens two different ways.
+// First, it counts opens assuming a wildcard is an open '('.
+// Next, it counts opens assuming a wildcard is a close ')'.
+// Runs in O(N) time and O(1) space.
 func WildcardParens(input string) bool {
-	var opens, wildcards int
+	var opensIfWildcardCloses, opensIfWildcardOpens int
 	for _, c := range input {
 		switch c {
 		case '(':
-			opens++
+			opensIfWildcardCloses++
+			opensIfWildcardOpens++
 		case ')':
-			switch {
-			case opens == 0 && wildcards < 1:
-				return false
-			case opens == 0:
-				wildcards--
-			default:
-				opens--
-			}
+			opensIfWildcardCloses--
+			opensIfWildcardOpens--
 		case '*':
-			wildcards++
+			opensIfWildcardCloses--
+			opensIfWildcardOpens++
+		}
+		if opensIfWildcardOpens < 0 {
+			break
+		}
+		// if a closing wildcard goes negative,
+		// assume it's an empty string.
+		if opensIfWildcardCloses < 0 {
+			opensIfWildcardCloses = 0
 		}
 	}
-	return opens == 0 || opens <= wildcards
+	return opensIfWildcardCloses == 0
 }


Test patch:
diff --git a/day142/problem_test.go b/day142/problem_test.go
index 519a5f6..88f0ab5 100644
--- a/day142/problem_test.go
+++ b/day142/problem_test.go
@@ -2,6 +2,7 @@ package day142
 
 import "testing"
 
+// nolint
 var testcases = []struct {
 	input    string
 	balanced bool
@@ -17,6 +18,7 @@ var testcases = []struct {
 	{"***********************", true},
 	{"****)))", true},
 	{"****)))))", false},
+	{"*(", false},
 }
 
 func TestWildcardParens(t *testing.T) {
Repository: go-gorm/gorm
Pull request #5155 (2022-03-14 04:41:57)

fix when index name is "type", parseFieldIndexes will set index TYPE is "TYPE"
<!--
Make sure these boxes checked before submitting your pull request.

For significant changes, please open an issue to make an agreement on an implementation design/plan first before starting it.
-->

- [x] Do only one thing
- [x] Non breaking API changes
- [x] Tested

### What did this pull request do?
```
Name7        string `gorm:"index:type"``
```
call `AutoMigrate`,when index name is type, `parseFieldIndexes` will parse index TYPE is "TYPE", because `ParseTagSetting`'s params is `type`, it will return `map[TYPE]TYPE`,,so we should exclude index name in call `ParseTagSetting`'s params

error generate sql 
```
`CREATE INDEX `type` ON `xxxx`(`xxx`,`type`) USING TYPE`
```
<!--
provide a general description of the code changes in your pull request
-->

### User Case Description
```
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE' at line 1", "elapsed": 0.000959069, "rows": 0, "sql": "CREATE INDEX `type` ON `xxxxxxxxx`(`xxxxx`,`type`) USING TYPE
```

https://github.com/go-gorm/playground/pull/446
<!-- Your use case -->



labulakalia: https://github.com/go-gorm/playground/runs/5532362884?check_suite_focus=true 

Patch:
diff --git a/schema/index.go b/schema/index.go
index 5f775f3..16d096b 100644
--- a/schema/index.go
+++ b/schema/index.go
@@ -89,11 +89,12 @@ func parseFieldIndexes(field *Field) (indexes []Index) {
 			k := strings.TrimSpace(strings.ToUpper(v[0]))
 			if k == "INDEX" || k == "UNIQUEINDEX" {
 				var (
-					name      string
-					tag       = strings.Join(v[1:], ":")
-					idx       = strings.Index(tag, ",")
-					settings  = ParseTagSetting(tag, ",")
-					length, _ = strconv.Atoi(settings["LENGTH"])
+					name       string
+					tag        = strings.Join(v[1:], ":")
+					idx        = strings.Index(tag, ",")
+					tagSetting = strings.Join(strings.Split(tag, ",")[1:], ",")
+					settings   = ParseTagSetting(tagSetting, ",")
+					length, _  = strconv.Atoi(settings["LENGTH"])
 				)
 
 				if idx == -1 {


Test patch:
diff --git a/schema/index_test.go b/schema/index_test.go
index bc6bb8b..3c4582b 100644
--- a/schema/index_test.go
+++ b/schema/index_test.go
@@ -18,6 +18,7 @@ type UserIndex struct {
 	Age          int64  `gorm:"index:profile,expression:ABS(age),option:WITH PARSER parser_name"`
 	OID          int64  `gorm:"index:idx_id;index:idx_oid,unique"`
 	MemberNumber string `gorm:"index:idx_id,priority:1"`
+	Name7        string `gorm:"index:type"`
 }
 
 func TestParseIndex(t *testing.T) {
@@ -78,6 +79,11 @@ func TestParseIndex(t *testing.T) {
 			Class:  "UNIQUE",
 			Fields: []schema.IndexOption{{Field: &schema.Field{Name: "OID"}}},
 		},
+		"type": {
+			Name:   "type",
+			Type:   "",
+			Fields: []schema.IndexOption{{Field: &schema.Field{Name: "Name7"}}},
+		},
 	}
 
 	indices := user.ParseIndexes()
Repository: go-gorm/gorm
Pull request #6839 (2024-02-14 12:05:18)

Fix: panic on nullable value with multiple foreign key usage


<!--
Make sure these boxes checked before submitting your pull request.

For significant changes, please open an issue to make an agreement on an implementation design/plan first before starting it.
-->

- [x] Do only one thing
- [x] Non breaking API changes
- [x] Tested

### What did this pull request do?

Fixes issue #6016.

### User Case Description

It panics on prepare request stage in some rare cases



Patch:
diff --git a/utils/utils.go b/utils/utils.go
index a4d8ac2..347a331 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -74,7 +74,11 @@ func ToStringKey(values ...interface{}) string {
 		case uint:
 			results[idx] = strconv.FormatUint(uint64(v), 10)
 		default:
-			results[idx] = fmt.Sprint(reflect.Indirect(reflect.ValueOf(v)).Interface())
+			results[idx] = "nil"
+			vv := reflect.ValueOf(v)
+			if vv.IsValid() && !vv.IsZero() {
+				results[idx] = fmt.Sprint(reflect.Indirect(vv).Interface())
+			}
 		}
 	}
 


Test patch:
diff --git a/utils/utils_test.go b/utils/utils_test.go
index d048682..8ff42af 100644
--- a/utils/utils_test.go
+++ b/utils/utils_test.go
@@ -48,8 +48,10 @@ func TestToStringKey(t *testing.T) {
 	}{
 		{[]interface{}{"a"}, "a"},
 		{[]interface{}{1, 2, 3}, "1_2_3"},
+		{[]interface{}{1, nil, 3}, "1_nil_3"},
 		{[]interface{}{[]interface{}{1, 2, 3}}, "[1 2 3]"},
 		{[]interface{}{[]interface{}{"1", "2", "3"}}, "[1 2 3]"},
+		{[]interface{}{[]interface{}{"1", nil, "3"}}, "[1 <nil> 3]"},
 	}
 	for _, c := range cases {
 		if key := ToStringKey(c.values...); key != c.key {