{"record":{"id":"65474741d8b85a68","repo":"ppy/osu","slug":"use-override-with-hittype-parameter-instead","errorCode":null,"errorMessage":"Use override with HitType parameter instead","messagePattern":"Use override with HitType parameter instead","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"osu.Game.Rulesets.Taiko/UI/DrumSampleTriggerSource.cs","lineNumber":59,"sourceCode":"                return;\r\n\r\n            var baseSample = hitObject.CreateHitSampleInfo(hitType == HitType.Rim ? HitSampleInfo.HIT_CLAP : HitSampleInfo.HIT_NORMAL);\r\n\r\n            if (strong)\r\n            {\r\n                PlaySamples(new ISampleInfo[]\r\n                {\r\n                    baseSample,\r\n                    hitObject.CreateHitSampleInfo(hitType == HitType.Rim ? HitSampleInfo.HIT_WHISTLE : HitSampleInfo.HIT_FINISH)\r\n                });\r\n            }\r\n            else\r\n            {\r\n                PlaySamples(new ISampleInfo[] { baseSample });\r\n            }\r\n        }\r\n\r\n        public override void Play() => throw new InvalidOperationException(@\"Use override with HitType parameter instead\");\r\n\r\n        protected override void ApplySampleInfo(SkinnableSound hitSound, ISampleInfo[] samples)\r\n        {\r\n            base.ApplySampleInfo(hitSound, samples);\r\n\r\n            hitSound.Balance.Value = -0.05 + RNG.NextDouble(0.1);\r\n        }\r\n    }\r\n\r\n    public enum SampleBalance\r\n    {\r\n        Left,\r\n        Centre,\r\n        Right\r\n    }\r\n}\r\n","sourceCodeStart":41,"sourceCodeEnd":76,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game.Rulesets.Taiko/UI/DrumSampleTriggerSource.cs#L41-L76","documentation":"DrumSampleTriggerSource overrides the parameterless Play() method to throw InvalidOperationException because this trigger source must know whether a hit was a Rim (whistle) or Centre (finish) hit to select the correct drum sample. The class provides a Play(HitType) overload instead. Calling the inherited parameterless Play() is a programming error.","triggerScenarios":"Calling drumSampleTriggerSource.Play() without a HitType argument. This commonly happens when generic code holds a reference to the base class (HitSampleTriggerSource or Drawable) and dispatches through the parameterless Play() without knowing the concrete type requires a HitType.","commonSituations":"Polymorphic code that calls Play() on a base HitSampleTriggerSource reference; refactoring that accidentally routes through the base method; code that was written for a non-Taiko trigger source and reused without adaptation.","solutions":["Call the Play(HitType) overload: drumSampleTriggerSource.Play(hitType).","If working through a base HitSampleTriggerSource reference, cast to DrumSampleTriggerSource or resolve the HitType before calling.","If polymorphic dispatch is unavoidable, check the runtime type and branch to the correct overload."],"exampleFix":"// before — base reference, parameterless Play\nHitSampleTriggerSource source = GetTriggerSource();\nsource.Play(); // throws if source is DrumSampleTriggerSource\n\n// after — use the HitType overload\nif (source is DrumSampleTriggerSource drumSource)\n    drumSource.Play(hitType);\nelse\n    source.Play();","handlingStrategy":"type-guard","validationCode":"// Check the concrete type before calling Play\nif (triggerSource is DrumSampleTriggerSource drumSource)\n    drumSource.Play(hitType);\nelse\n    triggerSource.Play();","typeGuard":"static bool RequiresHitTypeParameter(HitSampleTriggerSource source)\n    => source is DrumSampleTriggerSource;","tryCatchPattern":null,"preventionTips":["When working with DrumSampleTriggerSource, always use the Play(HitType) overload.","If dispatching through a base reference, check the runtime type and branch to the correct overload.","Consider adding a unit test that verifies Play(HitType) works and Play() throws for this type."],"tags":["taiko-ruleset","audio","api-design","polymorphism"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}