@@ -292,22 +292,23 @@ extension MEProgram.Builder {
292292 }
293293
294294 mutating func buildBackreference(
295- _ cap: CaptureRegister
295+ _ cap: CaptureRegister ,
296+ isScalarMode: Bool
296297 ) {
297298 instructions. append (
298- . init( . backreference, . init( capture: cap) ) )
299+ . init( . backreference, . init( capture: cap, isScalarMode : isScalarMode ) ) )
299300 }
300301
301- mutating func buildUnresolvedReference( id: ReferenceID ) {
302- buildBackreference ( . init( 0 ) )
302+ mutating func buildUnresolvedReference( id: ReferenceID , isScalarMode : Bool ) {
303+ buildBackreference ( . init( 0 ) , isScalarMode : isScalarMode )
303304 unresolvedReferences [ id, default: [ ] ] . append ( lastInstructionAddress)
304305 }
305306
306- mutating func buildNamedReference( _ name: String ) throws {
307+ mutating func buildNamedReference( _ name: String , isScalarMode : Bool ) throws {
307308 guard let index = captureList. indexOfCapture ( named: name) else {
308309 throw RegexCompilationError . uncapturedReference
309310 }
310- buildBackreference ( . init( index) )
311+ buildBackreference ( . init( index) , isScalarMode : isScalarMode )
311312 }
312313
313314 // TODO: Mutating because of fail address fixup, drop when
@@ -456,8 +457,10 @@ fileprivate extension MEProgram.Builder {
456457 throw RegexCompilationError . uncapturedReference
457458 }
458459 for use in uses {
460+ let ( isScalarMode, _) = instructions [ use. rawValue] . payload. captureAndMode
459461 instructions [ use. rawValue] =
460- Instruction ( . backreference, . init( capture: . init( offset) ) )
462+ Instruction ( . backreference,
463+ . init( capture: . init( offset) , isScalarMode: isScalarMode) )
461464 }
462465 }
463466 }
0 commit comments