Commit 34bf0ae
fix(lift-webkit): fix Scala 3 snippet instantiation with type-safe reflection
Resolves snippet class instantiation failures in Scala 3.3.6 that were
causing ClassCastException when constructing snippet instances via reflection.
Root Cause:
Scala 3's stricter type inference would default generic type parameter T
to Nothing when calling makeOne[T] without explicit type context, causing
attempts to cast snippet instances to scala.runtime.Nothing$ which failed.
Solution:
- Changed ConstructorType.makeOne methods to return AnyRef instead of T
- Added targetClass parameter to ConstructorType trait and implementations
- Used Class.cast() for runtime type verification before final cast
- Moved final asInstanceOf[T] to call site where type context is available
- Fixed variable shadowing issue (paramClz vs clz) in constructFrom
- Enhanced error handling for ClassCastException and InvocationTargetException
The fix uses Class.cast() which performs proper runtime type checking,
making the code more type-safe while working correctly in both Scala 2.13
and Scala 3.3.6.
Tests Fixed:
- OneShot: all 6 tests now pass (snippet callbacks execute correctly)
- ToHeadUsages: all 12 tests now pass (snippet rendering works)
- WebSpecSpec: template processing test un-pended and passing
- Full test suite: 281 tests pass on Scala 3.3.6 (previously had failures)
- No regressions: 282 tests pass on Scala 2.13 (unchanged)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 2e623ff commit 34bf0ae
3 files changed
Lines changed: 40 additions & 24 deletions
File tree
- web/webkit/src
- main/scala/net/liftweb/http
- test/scala-3/net/liftweb/mockweb
Lines changed: 22 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
159 | 161 | | |
160 | 162 | | |
161 | 163 | | |
| |||
1355 | 1357 | | |
1356 | 1358 | | |
1357 | 1359 | | |
1358 | | - | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1359 | 1369 | | |
1360 | 1370 | | |
1361 | 1371 | | |
| |||
Lines changed: 15 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
343 | 345 | | |
344 | 346 | | |
345 | 347 | | |
346 | 348 | | |
347 | | - | |
348 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
349 | 353 | | |
350 | 354 | | |
351 | 355 | | |
352 | 356 | | |
353 | 357 | | |
354 | | - | |
355 | | - | |
356 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
357 | 362 | | |
358 | 363 | | |
359 | 364 | | |
360 | 365 | | |
361 | 366 | | |
362 | | - | |
363 | | - | |
364 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
365 | 371 | | |
366 | 372 | | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
157 | | - | |
158 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
0 commit comments